home *** CD-ROM | disk | FTP | other *** search
- \bigskip
- \bigskip
- {\magonebf 2.2 Real Numbers (real)}
-
- Data type $real$ is the LEDA equivalent of the \CC built in type $double$.
- Variables of the data type $real$ behave exactly like variables of type
- $double$ (arithmetic, compare and input/output operators are the same).
- The only difference between $real$ and $double$ lies in the fact that
- $real$ is allowed as subtype (type parameter) for generic data types.
- There is automatic type conversion from $real$ to $double$. Thus, all
- functions taking $double$ arguments accept also arguments of type $real$
- and vice versa. In particular the mathematical functions declared in
- $<$math.h$>$ can be used with $real$ arguments.
- The \ $\tilde{}$ operator is defined to explicitly convert an instance of
- the data type $real$ to a \CC $double$. This allows the use of the \CC
- functions $printf$ and $form$ for formatted ouput of reals.
-
- \bigskip
- Example:
-
- \#include $<$math.h$>$
- \medskip
- \cleartabs
- \+$real$ $r = 3.1415$;\cr
- \+$real$ $s = $sin$(r)$;\cr
- \+cout $<<$ form(``sine of \%f = \%f\n", $\tilde{}\ r$, $\tilde{}\ s$);\cr
-