Float

Inherits from: Object

IEEE 754 double-precision floating-point numbers. Arithmetic operators (+, -, *, /) and comparisons (<, >) are VM primitives and accept both Float and SmallInteger arguments.

Test
1.5 + 2.5 >>> 4.0
2.5 negated >>> -2.5
3.0 max: 5.0 >>> 5
0.0 isZero >>> true
0.0 sin >>> 0
0.0 cos >>> 1
0.0 tan >>> 0
0.0 asin >>> 0
1.0 acos >>> 0
0.0 atan >>> 0
1.0 atan2: 1.0 >>> 0.7853981633974483
1.0 ln >>> 0
1.0 log10 >>> 0
8.0 log: 2.0 >>> 3
0.0 exp >>> 1
2.0 pow: 10.0 >>> 1024
Example
"Compute the hypotenuse of a 3-4-5 right triangle"
((3.0 * 3.0) + (4.0 * 4.0)) sqrt

Class Methods

primitives

class e

Return Euler's number e (2.71828...).

class infinity

Return positive infinity.

class nan

Return NaN (not a number).

class pi

Return the constant pi (3.14159...).

Instance Methods

primitives

*

Return the product of the receiver and the argument.

+

Return the sum of the receiver and the argument.

-

Return the difference of the receiver and the argument.

/

Return the receiver divided by the argument.

<

Return true if the receiver is less than the argument.

>

Return true if the receiver is greater than the argument.

acos

Return the arc cosine of the receiver. Result in radians.

asin

Return the arc sine of the receiver. Result in radians.

atan

Return the arc tangent of the receiver. Result in radians.

atan2:

Return the arc tangent of y/x (receiver is y, argument is x), using the signs of both to determine the quadrant. Result in radians.

cos

Return the cosine of the receiver (in radians).

exp

Return e raised to the power of the receiver.

ln

Return the natural logarithm (base e) of the receiver.

log10

Return the base-10 logarithm of the receiver.

log:

Return the logarithm of the receiver in the given base.

pow:

Return the receiver raised to the given power.

primCeiling
primFloor
primPrintString
primRounded
primTruncated
sin

Return the sine of the receiver (in radians).

sqrt

Return the square root of the receiver.

tan

Return the tangent of the receiver (in radians).

uncategorized

abs

Return the absolute value of the receiver.

Test
(0.0 - 5.5) abs >>> 5.5
3.14 abs >>> 3.14
0.0 abs >>> 0
ceiling

Return the smallest integer greater than or equal to the receiver. Delegates to the primCeiling VM primitive.

Example
3.2 ceiling   "=> 4"
floor

Return the largest integer less than or equal to the receiver. Delegates to the primFloor VM primitive.

Example
3.7 floor    "=> 3"
isZero

Return true if the receiver is equal to zero.

Test
0.0 isZero >>> true
3.14 isZero >>> false
max:

Return the larger of the receiver and other.

Test
3.0 max: 5.0 >>> 5
5.0 max: 3.0 >>> 5
min:

Return the smaller of the receiver and other.

Test
3.0 min: 5.0 >>> 3
5.0 min: 3.0 >>> 3
negated

Return the arithmetic negation of the receiver.

Test
2.5 negated >>> -2.5
0.0 negated >>> -0
(0.0 - 7.0) negated >>> 7
negative

Return true if the receiver is less than zero.

Test
(0.0 - 1.0) negative >>> true
0.0 negative >>> false
3.0 negative >>> false
positive

Return true if the receiver is greater than zero.

Test
3.0 positive >>> true
0.0 positive >>> false
(0.0 - 1.0) positive >>> false
printString

Return a string representation of the receiver. Delegates to the primPrintString VM primitive, which uses Go's %g format (trailing zeroes are omitted, e.g. 5.0 prints as 5).

Example
3.14 printString   "=> '3.14'"
rounded

Return the nearest integer to the receiver (rounding half away from zero). Returns a SmallInteger. Delegates to primRounded.

Example
3.5 rounded    "=> 4"
3.4 rounded    "=> 3"
sign

Return -1.0, 0.0, or 1.0 depending on whether the receiver is negative, zero, or positive.

Test
3.0 sign >>> 1
(0.0 - 3.0) sign >>> -1
0.0 sign >>> 0
truncated

Truncate the receiver toward zero, returning a SmallInteger. Delegates to primTruncated.

Example
3.9 truncated     "=> 3"
(0.0 - 3.9) truncated  "=> -3"