Float:
Filter:
Classes | Math

Float : SimpleNumber : Number : Magnitude : Object

64-bit Floating point number
Source: Float.sc

Description

A 64-bit double precision floating point number. Float inherits most of its behaviour from its superclass, SimpleNumber.

Note that despite its name, FloatArray only holds 32-bit (single precision) floats. For a raw array of 64-bit floats, use DoubleArray.

NOTE: The overflow/underflow behavior of a Float is undefined but usually inf/-inf, respectively, since most CPUs comply well enough IEEE-754 floating point. However, the overflow/underflow behavior is still usually handed to the hardware and thus can vary per system. This (overflow/underflow) occurs whenever the result of an operation does not fit in the range of values supported by the return type, in this case, a 64-bit floating point number.

Class Methods

Float.from32Bits(word)

Returns:

a new Float from a 32-bit word.

Float.from64Bits(hiWord, loWord)

Returns:

a new Float from a 64-bit word.

Inherited class methods

Instance Methods

.do(function)

iterates a Function from 0 to this - 1. See also: Integer: -do, Collection: -do

Arguments:

function

The function to iterate.

.reverseDo(function)

iterates function from this - 1 to 0

Arguments:

function

The function to iterate.

.clip(lo, hi)

Return this if lo <= this <= hi, otherwise return the nearest boundary: lo if this < lo, hi if this > hi.

Arguments:

lo

The low threshold of clipping.

hi

The high threshold of clipping.

.fold(lo, hi)

Fold this to [lo, hi].

Arguments:

lo

The low threshold of folding.

hi

The high threshold of folding.

.wrap(lo, hi)

Wrap this around [lo, hi) such that it falls in range. Equivalent to (this % (hi - lo)) + lo.

Arguments:

lo

The low threshold (inclusive) of wrapping.

hi

The high threshold (exclusive) of wrapping.

.coin

Let x be the receiver clipped to the range [0, 1]. With probability x, return true. With probability 1 - x, return false.

Returns:

Discussion:

See also: Randomness

.xrand2

Returns:

a random float from this.neg to this, excluding the value exclude.

.isFloat

Returns:

true since this is a Float.

.asFloat

Returns:

this since this is a Float.

.as32Bits

Returns:

an Integer which is the bit pattern of this as a 32bit single precision float

.high32Bits

Returns:

an Integer which is the bit pattern of high 32-bits of the 64-bit double precision floating point value

.low32Bits

Returns:

an Integer which is the bit pattern of high 32-bits of the 64-bit double precision floating point value

.asCompileString

Returns:

a string that when interpreted matches the receiver, if the number is within the range given in storeOn.

.asStringPrec(precision)

Returns a string representation of the number, with the desired precision (i.e. number of significant figures).

Discussion:

.dump

From superclass: Object

returns

   Float -1.000000   00000000 BFF00000
-> -1.0

The last two groups of an 8-digit integer are the raw hexadecimal representation of the 64-bit double value according to IEEE 754 Floating Point (https://ieeexplore.ieee.org/document/8766229). Each part is represented as follows:

                         raw hexadecimal representation
                           of the 64-bit double value
                         ––––––––––––––––––––––––––––––
Float   -1.000000        00000000              3FF00000
|       |                |                     |
class   decmial          significant part      exponent part
        representation   (mantissa)            with sign bit

Using Floats as replacement for Integers

In SuperCollider, Floats are 64 bits wide. Because an Integer is 32-bit, it can only capture integers in the range -2147483648 (-2^31) to 2147483647 (2^31 - 1).

Therefore, in some situations it can be useful to calculate with floats also when only whole numbers are needed. You can use 64-bit floats for integer calculations in the range ± 9007199254740992, or about ±2^53. Sometimes one can go even further (see example below).

Here is a classical example for an algorithm:

Testing the limits of 64-bit float (2^53)

Inherited instance methods

Undocumented instance methods

*(aNumber, adverb)

+(aNumber, adverb)

-(aNumber, adverb)

.archiveAsCompileString

.schedBundle(bundle, server, timeOfRequest)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/schedBundle.sc

.switch( ... cases)