home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / man / real.tex < prev    next >
Encoding:
Text File  |  1991-11-15  |  1.1 KB  |  27 lines

  1. \bigskip
  2. \bigskip
  3. {\magonebf 2.2 Real Numbers (real)}     
  4.  
  5. Data type $real$ is the LEDA equivalent of the \CC built in type $double$. 
  6. Variables of the data type $real$ behave exactly like variables of type 
  7. $double$ (arithmetic, compare and input/output operators are the same).
  8. The only difference between $real$ and $double$ lies in the fact that 
  9. $real$ is allowed as subtype (type parameter) for generic data types. 
  10. There is automatic type conversion from $real$ to $double$. Thus, all 
  11. functions taking $double$ arguments accept also arguments of type $real$
  12. and vice versa. In particular the mathematical functions declared in 
  13. $<$math.h$>$ can be used with $real$ arguments.
  14. The \ $\tilde{}$ operator is defined to explicitly convert an instance of 
  15. the data type $real$ to a \CC $double$. This allows the use of the \CC
  16. functions $printf$ and $form$ for formatted ouput of reals. 
  17.  
  18. \bigskip
  19. Example:
  20.  
  21. \#include $<$math.h$>$
  22. \medskip
  23. \cleartabs
  24. \+$real$ $r = 3.1415$;\cr
  25. \+$real$ $s = $sin$(r)$;\cr
  26. \+cout $<<$ form(``sine of \%f = \%f\n", $\tilde{}\ r$, $\tilde{}\ s$);\cr
  27.