Float! datatype

1. Abstract

Float! values represent 64-bit positive and negative numbers that contain a decimal point.

Floats span a range from -1.7E+308 to +1.7E+308.

Floats return #INF on overflow by design.

>> 1.8E+308
== 1.#INF

>> -1.8E+308
== -1.#INF

Dividing 0.0 by 0.0 results in 1.#NaN

Float! is a member of the following typesets: immediate!, number!, scalar!

2. Creation

Float! values can be created using literal syntax, or at runtime by using a make constructor or to conversion.

>> 100.1
== 100.1
>> make float! 1
== 1.0
>> to float! 1
== 1.0

3. Literal syntax

Zero or more digits, followed by a dot ., followed by one or more digits.

A comma can be used in place of the dot for the decimal point.

123,4

Note
A formed value will normalize a decimal comma to a decimal point as the decimal mark.

+ or - immediately before the first digit indicates the positive or negative sign of the float!.

+123.4

-123.4

Leading zeros are ignored.

>> +00123.4
== 123.4

Single quote ' is used as a place value separator for large values, and can appear anywhere after the first digit.

>> 60'000'12'3.4
== 60000123.4

A single quote ' immediately before or after the decimal point will raise an error.

>> 60'000'123'.4
*** Syntax Error: invalid integer! at "60'000'123'.4"
*** Where: do
*** Stack: load
>> 60'000'123.'4
*** Syntax Error: invalid integer! at "60'000'123.'4"
*** Where: do
*** Stack: load

4. Comparisons

All comparators can be applied on float!: =, ==, <>, >, <, >=, <=, =?. In addition, min, and max are also supported.

5. Conversion

A float value can be converted at runtime to integer! or string! by using a to conversion.

Note
The digits after the decimal point will be discarded when converting a float to an integer. No rounding will take place.
>> to integer! 123.4
== 123

>> to string! 123.4
== "123.4"

If float! and integer! are combined in an expression, the result will be a float! value.

>> 123.4 * 42
== 5182.8

6. Testing values

Use float? to check if a value is of the float! datatype.

>> float? 123.4
== true

Use type? to return the datatype of a given value.

>> type? 123.4
== float!

7. Pre-defined words

7.1. Functions

acos, asin, atan, atan2, cos, distance?, float?, sin, sqrt, tan, to-float

7.2. Natives

arccosine, arcsine, arctangent, arctangent2, as-pair, cosine, exp, log-10, log-2, log-e, sine, square-root, tangent

7.3. Operators

**

results matching ""

    No results matching ""