Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Compare this object to the specified for equality. This
method may be accessed via the == and != shortcut operators.
If not overridden the default implementation compares for
reference equality using the === operator. If this method
is overridden, then hash() must also be overridden such that
any two objects which return true for equals() must return
the same value for hash(). This method must accept null
and
return false.
Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return a string representation of this object.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
absReturn the absolute value of this float. If this value is positive then return this, otherwise return the negation.
Static
acosReturn the arc cosine.
Static
approxReturn 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
Optional
tolerance: numberStatic
asinReturn the arc sine.
Static
atanReturn the arc tangent.
Static
atan2Converts rectangular coordinates (x, y) to polar (r, theta).
Static
bitsReturn 64-bit representation according IEEE 754 floating-point double format bit layout. This method is paired with Float.makeBits.
Static
bits32Return 32-bit representation according IEEE 754 floating-point single format bit layout. This method is paired with Float.makeBits32.
Static
ceilReturns the smallest whole number greater than or equal to this number.
Static
clampClamp 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.
Static
compareCompare based on floating point value.
NaN works as follows:
<=>
operator NaN is always less than other values
and equal to itself (so sort works as expected)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
Static
cosReturn the cosine of this angle in radians.
Static
coshReturn the hyperbolic cosine.
Static
decrementDecrement by one. Shortcut is --a or a--.
Static
defDefault value is 0f.
Static
divDivide this by b. Shortcut is a/b.
Static
divDivide this by b. Shortcut is a/b.
Static
divDivide this by b. Shortcut is a/b.
Static
eFloat value for e which is the base of natural logarithms.
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
equalsStatic
expReturn e raised to this power.
Static
floorReturns the largest whole number less than or equal to this number.
Static
fromParse 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.
Optional
checked: booleanStatic
hashReturn bits().
Static
incrementIncrement by one. Shortcut is ++a or a++.
Static
isStatic
isReturn if this is negative zero value.
Static
localeGet the current locale's decimal separator. For example in the the US this is a dot.
Static
localeGet the current locale's separator for grouping thousands together. For example in the US this is a comma.
Static
localeGet the current locale's minus sign used to represent a negative number.
Static
localeGet the current locale's string representation for not-a-number.
Static
localeGet the current locale's string representation for negative infinity.
Static
localeGet the current locale's symbol for the percent sign.
Static
localeGet the current locale's string representation for positive infinity.
Static
logReturn natural logarithm of this number.
Static
log10Return base 10 logarithm of this number.
Static
makeMake a Float for the specified 64-bit representation according IEEE 754 floating-point double format bit layout. This method is paired with Float.bits.
Static
makeMake a Float for the specified 32-bit representation according IEEE 754 floating-point single format bit layout. This method is paired with Float.bits32.
Static
maxReturn the larger of this and the specified Float values.
Static
minReturn the smaller of this and the specified Float values.
Static
minusSubtract b from this. Shortcut is a-b.
Static
minusSubtract b from this. Shortcut is a-b.
Static
minusSubtract b from this. Shortcut is a-b.
Static
modReturn remainder of this divided by b. Shortcut is a%b.
Static
modReturn remainder of this divided by b. Shortcut is a%b.
Static
modReturn remainder of this divided by b. Shortcut is a%b.
Static
multMultiply this with b. Shortcut is a*b.
Static
multMultiply this with b. Shortcut is a*b.
Static
multMultiply this with b. Shortcut is a*b.
Static
nanFloat value for Not-A-Number.
Static
negateNegative of this. Shortcut is -a.
Static
negFloat value for negative infinity.
Static
normIf this value is negative zero then return normalized zero, otherwise return this value.
Static
piFloat value for pi which is the ratio of the circumference of a circle to its diameter.
Static
plusAdd this with b. Shortcut is a+b.
Static
plusAdd this with b. Shortcut is a+b.
Static
plusAdd this with b. Shortcut is a+b.
Static
posFloat value for positive infinity.
Static
powReturn this value raised to the specified power.
Static
randomGenerate a random float between 0.0 inclusive and 1.0 exclusive. Also see Int.random, Range.random, List.random, and util::Random.
Static
roundReturns the nearest whole number to this number.
Static
sinReturn sine of this angle in radians.
Static
sinhReturn hyperbolic sine.
Static
sqrtReturn square root of this value.
Static
tanReturn tangent of this angle in radians.
Static
tanhReturn hyperbolic tangent.
Static
toGet this Float as a Fantom code literal.
Static
toConvert this number to a Decimal.
Static
toConvert this angle in radians to an angle in degrees.
Static
toConvert this number to a Float.
Static
toConvert this number to an Int.
Static
toFormat 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
Optional
pattern: stringOptional
locale: LocaleStatic
toConvert this angle in degrees to an angle in radians.
Static
toGet 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".
Float is used to represent a 64-bit floating point number.