Fan

 

const final class

sys::Float

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

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

Slots

absSource

Float abs()

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

acosSource

Float acos()

Return the arc cosine.

approxSource

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

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 loose 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
asinSource

Float asin()

Return the arc sine.

atanSource

Float atan()

Return the arc tangent.

atan2Source

static Float atan2(Float y, Float x)

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

bitsSource

Int bits()

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

bits32Source

Int bits32()

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

ceilSource

Float ceil()

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

compareSource

override Int compare(Obj obj)

Overrides sys::Obj.compare

Compare based on floating point value.

cosSource

Float cos()

Return the cosine of this angle in radians.

coshSource

Float cosh()

Return the hyperbolic cosine.

decrementSource

Float decrement()

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

defValSource

static Float defVal

Default value is 0f.

divSource

Float div(Float b)

Divide this by b. Shortcut is a/b.

eSource

static Float e

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

equalsSource

override Bool equals(Obj? obj)

Overrides sys::Obj.equals

Return true if same float value. Unlike Java, NaN equals NaN.

expSource

Float exp()

Return e raised to this power.

floorSource

Float floor()

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

fromStrSource

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

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.

TODO: need spec - follow XML Schema literal definition

hashSource

override Int hash()

Overrides sys::Obj.hash

Return bits().

incrementSource

Float increment()

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

logSource

Float log()

Return natural logarithm of this number.

log10Source

Float log10()

Return base 10 logarithm of this number.

makeBitsSource

static Float makeBits(Int bits)

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.

makeBits32Source

static Float makeBits32(Int bits)

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.

maxSource

Float max(Float that)

Return the larger of this and the specified Float values.

minSource

Float min(Float that)

Return the smaller of this and the specified Float values.

minusSource

Float minus(Float b)

Subtract b from this. Shortcut is a-b.

modSource

Float mod(Float b)

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

multSource

Float mult(Float b)

Multiply this with b. Shortcut is a*b.

nanSource

static Float nan

Float value for Not-A-Number.

negInfSource

static Float negInf

Float value for negative infinity.

negateSource

Float negate()

Negative of this. Shortcut is -a.

piSource

static Float pi

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

plusSource

Float plus(Float b)

Add this with b. Shortcut is a+b.

posInfSource

static Float posInf

Float value for positive infinity.

powSource

Float pow(Float pow)

Return this value raised to the specified power.

roundSource

Float round()

Returns the nearest whole number to this number.

sinSource

Float sin()

Return sine of this angle in radians.

sinhSource

Float sinh()

Return hyperbolic sine.

sqrtSource

Float sqrt()

Return square root of this value.

tanSource

Float tan()

Return tangent of this angle in radians.

tanhSource

Float tanh()

Return hyperbolic tangent.

toCodeSource

Str toCode()

Get this Float as a Fan code literal.

toDegreesSource

Float toDegrees()

Convert this angle in radians to an angle in degrees.

toLocaleSource

Str toLocale(Str? pattern := null)

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
toRadiansSource

Float toRadians()

Convert this angle in degrees to an angle in radians.

toStrSource

override Str toStr()

Overrides sys::Obj.toStr

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".