[ Arithmetic | Reference Manual | Alphabetic Index ]

breal(+Number, -Result)

-Result is breal(+Number)

Converts Number into a breal number and unifies it with Result.
Number
A number.
Result
Output: bounded real number.

Description

The exact operation depends on the argument type:

If Number is an integer, the result is a tight breal whose float bounds enclose the integer. If the integer's magnitude is small enough to be accurately representable with a float, those bounds will be identical and the breal will have zero width. For IEEE 754 double representation the threshold is 9007199254740992.

If Number is a rational, the result is a breal whose float bounds enclose the exact value of the rational.

If Number is a float, the result is a zero-width breal with both bounds identical to Number. No outward-rounding is done, because the system has no way of knowing how inexact the float argument is. It therefore makes the (unrealistic) assumption that the value is accurate. [To manually construct wider intervals from a float, use breal_from_bounds/3. Moreover, the parser can configured to read numeric constants directly as safely rounded breals; see syntax_option read_floats_as_breals]

If Number is a breal, the result is Number itself.

Note: The implementation may sometimes round conservatively and not give the tightest possible result.

Modes and Determinism

Exceptions

(4) instantiation fault
Number is not instantiated (non-coroutining mode only).
(24) number expected
Number is not of a numeric type.

Examples

    % small integers and floats are assumed to be accurate:
    ?- Result is breal(25).
    Result = 25.0__25.0

    ?- Result is breal(1.5).
    Result = 1.5__1.5

    % rationals are conservatively rounded:
    ?- Result is breal(3_4).
    Result = 0.74999999999999989__0.75000000000000011

    % identity operation on breals:
    ?- Result is breal(1.0__1.01).
    Result = 1.0__1.01

    % rounding with large integers:
    ?- Result is breal(9999999999999999).
    Result = 9999999999999998.0__10000000000000002.0

See Also

integer / 2, float / 2, rational / 2, is / 2, breal_min / 2, breal_max / 2, breal_bounds / 3, breal_from_bounds / 3, breal / 1, read_floats_as_breals