x-lang

← Index

x/num/float

IEEE 754 floating-point arithmetic, homed on the Float class.

Literal syntax: 3.14. The generic operators dispatch float operands

through the type ops; mixed operands resolve by the from-relation.

Conversion

Predicates

Arithmetic

Comparisons

Math Functions

R7RS Predicates

number?

Test whether a value is a number (integer or float).

Parameters:

Returns: BOOL — True if x is a number

real?

Test whether a value is a real number (complex.x narrows this to exclude complexes).

Parameters:

Returns: BOOL — True if x is a real number

Class Float

(Float float? x)

Test whether a value is a float.

Parameters:

Returns: BOOL — True if x is a float

(Float inexact? x)

Test whether a value is inexact. Equivalent to float?.

Parameters:

Returns: BOOL — True if x is a float

(Float integer? x)

Test whether a value is an integer (the pre-float number? predicate).

Parameters:

Returns: BOOL — True if x is a native integer

(Float real? x)

Test whether a value is a real number (numbers minus complexes).

Parameters:

Returns: BOOL — True if x is real

(Float bits->str bits)

Render a raw IEEE 754 bit pattern as its decimal string – FFI plumbing; value-level work wants (Float from) / the printer.

Parameters:

Returns: STRING — Decimal string representation

(Float bits->int bits)

Truncate a raw IEEE 754 bit pattern to a machine integer – FFI plumbing; value-level work wants (Float ->int).

Parameters:

Returns: INT — Truncated integer value

(Float int->bits n)

The IEEE 754 bit pattern of an integer’s double value – FFI plumbing, NOT a float constructor; (Float from) builds instances.

Parameters:

Returns: INT — IEEE 754 double bit pattern

(Float str->bits s)

The IEEE 754 bit pattern of a decimal string’s double value – FFI plumbing, NOT a parser-to-instance; (Float from) builds instances (the old from-str name claimed FLOAT and returned bits, #66).

Parameters:

Returns: INT — IEEE 754 double bit pattern

(Float from x)

Construct a float from any convertible value, through the conversion catalog – the generic value door (was exact->inexact, #357). Raises tag ‘type when nothing converts.

Parameters:

Returns: FLOAT — Float instance

(Float ->int x)

Convert an inexact float to an exact integer by truncation.

Parameters:

Returns: INT — Truncated integer value

(Float + a b)

Add two floats (other numerics coerce).

Parameters:

Returns: FLOAT — Sum

(Float - a b)

Subtract two floats (other numerics coerce).

Parameters:

Returns: FLOAT — Difference

(Float * a b)

Multiply two floats (other numerics coerce).

Parameters:

Returns: FLOAT — Product

(Float / a b)

Divide two floats (other numerics coerce).

Parameters:

Returns: FLOAT — Quotient

(Float < a b)

Test whether a is less than b (other numerics coerce).

Parameters:

Returns: BOOL — True if a < b

(Float = a b)

Test whether a equals b (other numerics coerce).

Parameters:

Returns: BOOL — True if a equals b

(Float sin x)

Compute the sine of a float.

Parameters:

Returns: FLOAT — Sine of x

(Float cos x)

Compute the cosine of a float.

Parameters:

Returns: FLOAT — Cosine of x

(Float tan x)

Compute the tangent of a float.

Parameters:

Returns: FLOAT — Tangent of x

(Float sqrt x)

Compute the square root of a float.

Parameters:

Returns: FLOAT — Square root of x

(Float exp x)

Compute e raised to a power.

Parameters:

Returns: FLOAT — e raised to the power x

(Float log x)

Compute the natural logarithm of a float.

Parameters:

Returns: FLOAT — Natural logarithm of x

(Float abs x)

Compute the absolute value of a float.

Parameters:

Returns: FLOAT — Absolute value of x

(Float floor x)

Round a float down to the nearest integer.

Parameters:

Returns: FLOAT — Largest integer not greater than x

(Float ceil x)

Round a float up to the nearest integer.

Parameters:

Returns: FLOAT — Smallest integer not less than x

(Float round x)

Round a float to the nearest integer.

Parameters:

Returns: FLOAT — Nearest integer, ties away from zero

(Float trunc x)

Truncate a float toward zero.

Parameters:

Returns: FLOAT — Integer part of x

(Float rint x)

Round a float to the nearest integer using the current rounding mode.

Parameters:

Returns: FLOAT — Nearest integer

(Float asin x)

Compute the arc sine of a float.

Parameters:

Returns: FLOAT — Arc sine in radians

(Float acos x)

Compute the arc cosine of a float.

Parameters:

Returns: FLOAT — Arc cosine in radians

(Float atan x)

Compute the arc tangent of a float.

Parameters:

Returns: FLOAT — Arc tangent in radians

(Float pow base exponent)

Raise a float to a power.

Parameters:

Returns: FLOAT — base raised to the power exponent

(Float atan2 y x)

Compute the arc tangent of y/x, using signs to determine the quadrant.

Parameters:

Returns: FLOAT — Angle in radians

(Float log2 x)

Compute the base-2 logarithm of a float.

Parameters:

Returns: FLOAT — log2(x)

(Float log10 x)

Compute the base-10 logarithm of a float.

Parameters:

Returns: FLOAT — log10(x)

(Float hypot x y)

Compute sqrt(x^2 + y^2) without intermediate overflow (libm hypot).

Parameters:

Returns: FLOAT — The hypotenuse

(Float pi)

The circle constant pi, 3.14159265…

Returns: FLOAT — pi

(Float e)

Euler’s number e, 2.71828182…

Returns: FLOAT — e

(Float tau)

The turn constant tau = 2*pi, 6.28318530…

Returns: FLOAT — tau

(Float nan? x)

Is x a float NaN? #f for every non-float (an int is never NaN).

Parameters:

Returns: BOOL — #t only for a NaN float

(Float inf? x)

Is x a float infinity, either sign? #f for every non-float.

Parameters:

Returns: BOOL — #t only for an infinite float

(Float finite? x)

Is x a finite number? #t for machine INTs and finite floats; #f for float inf/NaN and for everything else (rational/bigint instances answer through their own classes).

Parameters:

Returns: BOOL — #t for machine ints and finite floats