const class sys::Float

sys::Obj
  sys::Num
    sys::Float

@Serializable { simple=true }

Source

Float is used to represent a 64-bit floating point number.

abs

Float abs()

Source

Return the absolute value of this float. If this value is positive then return this, otherwise return the negation.

acos

Float acos()

Source

Return the arc cosine.

approx

Bool approx(Float r, Float? tolerance := null)

Source

Return if this Float is approximately equal to the given Float by the specified tolerance. If tolerance is null, then it is computed using the magnitude of the two Floats. It is useful for comparing Floats since often they lose a bit of precision during manipulation. This method is equivalent to:

if (tolerance == null) tolerance = min(abs(this/1e6), abs(r/1e6))
(this - r).abs < tolerance
asin

Float asin()

Source

Return the arc sine.

atan

Float atan()

Source

Return the arc tangent.

atan2

static Float atan2(Float y, Float x)

Source

Converts rectangular coordinates (x, y) to polar (r, theta).

bits

Int bits()

Source

Return 64-bit representation according IEEE 754 floating-point double format bit layout. This method is paired with Float.makeBits.

bits32

Int bits32()

Source

Return 32-bit representation according IEEE 754 floating-point single format bit layout. This method is paired with Float.makeBits32.

ceil

Float ceil()

Source

Returns the smallest whole number greater than or equal to this number.

clamp

Float clamp(Float min, Float max)

Source

Clamp this float between the min and max. If its less than min then return min, if its greater than max return max, otherwise return this float itself.

compare

virtual override Int compare(Obj obj)

Source

Compare based on floating point value.

NaN works as follows:

  • for the <=> operator NaN is always less than other values and equal to itself (so sort works as expected)
  • for all other comparison operators anything compared against NaN is false (normal Java semanatics)

Examples:

Float.nan <=> Float.nan  =>  0
2f <=> Float.nan         =>  1
Float.nan <=> 2f         =>  -1
2f < Float.nan           =>  false
Float.nan < 2f           =>  false
Float.nan <= Float.nan   =>  false
cos

Float cos()

Source

Return the cosine of this angle in radians.

cosh

Float cosh()

Source

Return the hyperbolic cosine.

decrement

@Operator
Float decrement()

Source

Decrement by one. Shortcut is --a or a--.

defVal

const static Float defVal

Source

Default value is 0f.

div

@Operator
Float div(Float b)

Source

Divide this by b. Shortcut is a/b.

divDecimal

@Operator
Decimal divDecimal(Decimal b)

Source

Divide this by b. Shortcut is a/b.

divInt

@Operator
Float divInt(Int b)

Source

Divide this by b. Shortcut is a/b.

e

const static Float e

Source

Float value for e which is the base of natural logarithms.

equals

virtual override Bool equals(Obj? obj)

Source

Return true if same float value. Like Java, NaN != NaN. Also see compare.

exp

Float exp()

Source

Return e raised to this power.

floor

Float floor()

Source

Returns the largest whole number less than or equal to this number.

fromStr

static new fromStr(Str s, Bool checked := true)

Source

Parse a Str into a Float. Representations for infinity and not-a-number are "-INF", "INF", "NaN". This string format matches the lexical representation of Section 3.2.5 of XML Schema Part 2. If invalid format and checked is false return null, otherwise throw ParseErr.

hash

virtual override Int hash()

Source

Return bits().

increment

@Operator
Float increment()

Source

Increment by one. Shortcut is ++a or a++.

isNaN

Bool isNaN()

Source

Return if this is Float.nan. Also see compare.

isNegZero

Bool isNegZero()

Source

Return if this is negative zero value.

log

Float log()

Source

Return natural logarithm of this number.

log10

Float log10()

Source

Return base 10 logarithm of this number.

makeBits

static Float makeBits(Int bits)

Source

Make a Float for the specified 64-bit representation according IEEE 754 floating-point double format bit layout. This method is paired with Float.bits.

makeBits32

static Float makeBits32(Int bits)

Source

Make a Float for the specified 32-bit representation according IEEE 754 floating-point single format bit layout. This method is paired with Float.bits32.

max

Float max(Float that)

Source

Return the larger of this and the specified Float values.

min

Float min(Float that)

Source

Return the smaller of this and the specified Float values.

minus

@Operator
Float minus(Float b)

Source

Subtract b from this. Shortcut is a-b.

minusDecimal

@Operator
Decimal minusDecimal(Decimal b)

Source

Subtract b from this. Shortcut is a-b.

minusInt

@Operator
Float minusInt(Int b)

Source

Subtract b from this. Shortcut is a-b.

mod

@Operator
Float mod(Float b)

Source

Return remainder of this divided by b. Shortcut is a%b.

modDecimal

@Operator
Decimal modDecimal(Decimal b)

Source

Return remainder of this divided by b. Shortcut is a%b.

modInt

@Operator
Float modInt(Int b)

Source

Return remainder of this divided by b. Shortcut is a%b.

mult

@Operator
Float mult(Float b)

Source

Multiply this with b. Shortcut is a*b.

multDecimal

@Operator
Decimal multDecimal(Decimal b)

Source

Multiply this with b. Shortcut is a*b.

multInt

@Operator
Float multInt(Int b)

Source

Multiply this with b. Shortcut is a*b.

nan

const static Float nan

Source

Float value for Not-A-Number.

negInf

const static Float negInf

Source

Float value for negative infinity.

negate

@Operator
Float negate()

Source

Negative of this. Shortcut is -a.

normNegZero

Float normNegZero()

Source

If this value is negative zero then return normalized zero, otherwise return this value.

pi

const static Float pi

Source

Float value for pi which is the ratio of the circumference of a circle to its diameter.

plus

@Operator
Float plus(Float b)

Source

Add this with b. Shortcut is a+b.

plusDecimal

@Operator
Decimal plusDecimal(Decimal b)

Source

Add this with b. Shortcut is a+b.

plusInt

@Operator
Float plusInt(Int b)

Source

Add this with b. Shortcut is a+b.

posInf

const static Float posInf

Source

Float value for positive infinity.

pow

Float pow(Float pow)

Source

Return this value raised to the specified power.

random

static Float random()

Source

Generate a random float between 0.0 inclusive and 1.0 exclusive. Also see Int.random, Range.random, List.random, and Random.

round

Float round()

Source

Returns the nearest whole number to this number.

sin

Float sin()

Source

Return sine of this angle in radians.

sinh

Float sinh()

Source

Return hyperbolic sine.

sqrt

Float sqrt()

Source

Return square root of this value.

tan

Float tan()

Source

Return tangent of this angle in radians.

tanh

Float tanh()

Source

Return hyperbolic tangent.

toCode

Str toCode()

Source

Get this Float as a Fantom code literal.

toDegrees

Float toDegrees()

Source

Convert this angle in radians to an angle in degrees.

toLocale

Str toLocale(Str? pattern := null, Locale locale := Locale.cur())

Source

Format this floating point number for the current locale. If pattern is null, then the locale's default pattern is used. Also see Num.localeDecimal, Num.localeGrouping, etc.

The pattern format:

#   optional digit
0   required digit
.   decimal point
,   grouping separator (only last one before decimal matters)

Examples:

12345.786f.toLocale("#,###.0")  =>  12,345.8
7.1234f.toLocale("#.000")       =>  7.123
0.1234f.toLocale("#.000")       =>  .123
0.1234f.toLocale("0.00")        =>  0.12
70.12f.toLocale("0.0000")       =>  70.1200
toRadians

Float toRadians()

Source

Convert this angle in degrees to an angle in radians.

toStr

virtual override Str toStr()

Source

Get string representation according to the lexical representation defined by Section 3.2.5 of XML Schema Part 2. Representations for infinity and not-a-number are "-INF", "INF", "NaN".