Real



next up previous contents index
Next: Char Up: No Title Previous: Int

Real

A "real" is an immutable, floating-point number. It is represented by a subset of the IEEE single-precision format floating-point numbers, with the following changes: The following equates from the Theta environment describe specifics of the range, granularity and format of the real numbers as represented in Theta:
real_emin           an integer value indicating the smallest binary exponent.
real_emax           an integer value indicating the largest binary exponent.
real_precision      an integer value indicating the number of binary digits of precision available
                    \tex{in} reals.
The following values describe the range of values and the granularity.
real_max            a real value indicating the maximum value of a real.
real_min            a real value indicating the minimum value of a normalized real number.
real_epsilon        a real value indicating the value of a bit in the least significant position
                    \tex{in} the fraction \tex{when} the exponent is zero.
real_round_style    an enumerated value indicating the rounding style: 
                                  real_round_toward_zero
                                  real_round_toward_minus_infinity
                                  real_round_other
Note that
real_max        = \tex{$(1 - 2^{-\mbox{\small real\_precision}}) * 2^{\mbox{\small real\_emax}}$}
real_min        = \tex{$2^{(\mbox{\small real\_emin}-1)}$}
real_epsilon    = \tex{$2^{(1-\mbox{\small real\_precision})}$}
"Real" literals can have any one of the following forms:
<real_literal> -> [ <digits> ] "." <digits> [ <exponent> ]
               |  <digits> <exponent>
<exponent> -> "e" [ "+" | "-" ] <digits>
           |  "E" [ "+" | "-" ] <digits>
where digits is a non-empty sequence of digits in the range 0-9. No spaces are allowed in the middle of a real_literal. Here are some examples of legal real_literals:
2.6
25.0
.05
5.2e-3
5.2e+3
2e10
.02E2
.0E5

Note that a decimal point must be followed by one or more digits, so the following are _not_ legal real literals:

1.
45.e6

Methods for type "real"

  negate ( ) returns (real)
      % effects   returns -self.

  add (x: real) returns (real) signals (overflow, underflow)
      % effects   returns self + x.  Signals overflow if result is too big to be represented.
      %           Signals underflow if result it too close to zero to be represented.
    
  subtract (x: real) returns (real) signals (overflow, underflow)
      % effects   returns self - x.  Signals overflow if result is too big to be represented.
      %           Signals underflow if result it too close to zero to be represented.

  multiply (x: real) returns (real) signals (overflow, underflow)
      % effects   returns self * x.  Signals overflow if result is too big to be represented.
      %           Signals underflow if result it too close to zero to be represented.

  divide (x: real) returns (real) signals (overflow, underflow, zero_divide)
      % effects   returns self / x.  Signals overflow if result is too big to be represented.
      %           Signals underflow if result it too close to zero to be represented.
      %           Signals zero_divide if x = 0.

  power (x: real) returns (real) signals (overflow, underflow, complex_result, zero_divide)
      % effects   returns self raised to the x power.
      %		  Signals overflow if result is too big to be represented.
      %           Signals underflow if result it too close to zero to be represented.
      %		  Signals zero_divide if self = 0 and x < 0.
      %		  Signals complex_result if self < 0 and x has a fractional component.

  abs ( ) returns (real)
      % effects   returns the absolute value of self.

  exponent ( ) returns (int) signals (undefined)
      % effects   returns n such that \tex{$2^{n-1} \le \mbox{self} < 2^{n}$}
      %           Signals undefined if self = 0.

  mantissa ( ) returns (real)
      % effects   returns \tex{\(x\)} such that \tex{\( x \times 2^{{\thet self.exponent()}} \; = \; {\thet self}\)}

  max (x: real) returns (real)
      % effects   returns the larger of self and x

  min (x: real) returns (real)
      % effects   returns the smaller of self and x

  to_int ( ) returns (int) signals (overflow)
      % effects   returns self rounded to the nearest integer (towards zero, in the case of a tie).
      %           Signals overflow if the rounded number can not be represented as an integer.

  floor ( ) returns (real)
      % effects   returns self rounded toward negative infinity.

  ceiling ( ) returns (real)
      % effects   returns self rounded toward positive infinity.
  
  lt (x: real) returns (bool)
      % effects   returns (self < x)

  le (x: real) returns (bool)
      % effects   returns (self \tex{$\le$} x)

  gt (x: real) returns (bool)
      % effects   returns (self > x)

  ge (x: real) returns (bool)
      % effects   returns (self \tex{$\ge$} x)

  equal (x: real) returns (bool)
      % effects   returns (self = x)

  similar (x: real) returns (bool)
      % effects   returns (self = x)

  copy ( ) returns (real)
      % effects   returns self

  unparse ( ) returns (string)
      % effects   returns the string representation of a literal corresponding to self.
      %           The general form is [-]intpart.fractpart[e+/-exp].



theta-questions@lcs.mit.edu