schemeNumber.js

Exports

SchemeNumber

Depends

biginteger.js for BigInteger

Summary
schemeNumber.jsSchemeNumber
SchemeNumberA number object as defined by the Scheme language.
VERSIONLibrary version as an array of integers.
raiseFunction that translates a Scheme exception to ECMAScript.
maxIntegerDigitsMaximum size of integers created by the fn.expt(z1, z2) function.
toString(radix)Converts this Scheme number to a string.
toFixed(fractionDigits)Returns this Scheme number as a string with fractionDigits digits after the decimal point.
toExponential(fractionDigits)Converts this Scheme number to scientific "e" notation with fractionDigits digits after the decimal point.
toPrecision(precision)Converts this Scheme number to decimal (possibly "e" notation) with precision significant digits.
fnContainer of Scheme functions.
Function listAll Scheme functions are specified by R6RS.
Scheme functionsElements of fn.
fn["number?"](obj)Returns true if obj is a Scheme number.
fn["complex?"](obj)Returns true if obj is a Scheme complex number.
fn["real?"](obj)Returns true if obj is a Scheme real number.
fn["rational?"](obj)Returns true if obj is a Scheme rational number.
fn["integer?"](obj)Returns true if obj is a Scheme integer.
fn["real-valued?"](obj)Returns true if obj is a Scheme complex number and fn["imag-part"](obj) is zero.
fn["rational-valued?"](obj)Returns true if obj is real-valued and fn["real-part"](obj) is rational.
fn["integer-valued?"](obj)Returns true if obj is real-valued and fn["real-part"](obj) is an integer.
fn["exact?"](z)Returns true if z is exact.
fn["inexact?"](z)Returns true if z is inexact.
fn.inexact(z)Returns an inexact number equal to z.
fn.exact(z)Returns an exact number equal to z.
fn["eqv?"](obj1, obj2)Returns true if obj1 === obj2 or both arguments are Scheme numbers and behave identically.
fn["="](z, z, z...)Returns true if all arguments are mathematically equal, though perhaps differing in exactness.
fn["<"](x, x, x...)Returns true if arguments increase monotonically.
fn[">"](x, x, x...)Returns true if arguments decrease monotonically.
fn["<="](x, x, x...)Returns true if arguments are monotonically nondecreasing.
fn[">="](x, x, x...)Returns true if arguments are monotonically nonincreasing.
fn["zero?"](z)Returns true if z equals zero.
fn["positive?"](x)Returns true if x is positive.
fn["negative?"](x)Returns true if x is negative.
fn["odd?"](n)Returns true if n is odd.
fn["even?"](n)Returns true if n is even.
fn["finite?"](x)Returns true if x is finite.
fn["infinite?"](x)Returns true if x is plus or minus infinity.
fn["nan?"](x)Returns true if x is a NaN.
fn.max(x, x...)Returns the greatest argument.
fn.min(x, x...)Returns the least argument.
fn["+"](z...)Returns the sum of the arguments.
fn["*"](z...)Returns the product of the arguments.
fn["-"](z)Returns the negation of z (-z).
fn["-"](z1, z2...)Returns z1 minus the sum of the number(s) z2.
fn["/"](z)Returns the reciprocal of z (1 / z).
fn["/"](z1, z2...)Returns z1 divided by the product of the number(s) z2.
fn.abs(x)Returns the absolute value of x.
fn["div-and-mod"](x, y)Returns fn.div(x, y) and fn.mod(x, y).
fn.div(x, y)Returns the greatest integer less than or equal to x / y.
fn.mod(x, y)Returns x - (y * fn.div(x, y)).
fn["div0-and-mod0"](x, y)Returns fn.div0(x, y) and fn.mod0(x, y).
fn.div0(x, y)Returns the integer nearest x / y, ties go lower.
fn.mod0(x, y)Returns x - (y * fn.div0(x, y)).
fn.gcd(n...)Returns the arguments’ greatest common non-negative divisor.
fn.lcm(n...)Returns the arguments’ least common positive multiple.
fn.numerator(q)Returns q * fn.denominator(q).
fn.denominator(q)Returns the smallest positive integer which when multiplied by q yields an integer.
fn.floor(x)Returns the greatest integer not greater than x.
fn.ceiling(x)Returns the least integer not less than x.
fn.truncate(x)Returns the closest integer between 0 and x.
fn.round(x)Returns the closest integer to x, ties go even.
fn.rationalize(x, y)Returns the simplest fraction within y of x.
fn.exp(z)Returns e to the z.
fn.log(z)Returns the natural logarithm of z.
fn.log(z1, z2)Returns the base-z2 logarithm of z1.
fn.sin(z)Returns the sine of z.
fn.cos(z)Returns the cosine of z.
fn.tan(z)Returns the tangent of z.
fn.asin(z)Returns a number whose sine is z.
fn.acos(z)Returns a number whose cosine is z.
fn.atan(z)Returns a number whose tangent is z.
fn.atan(y, x)Returns the angle that passes through (x,y).
fn.sqrt(z)Returns the square root of z.
fn["exact-integer-sqrt"](k)Returns maximal exact s and non-negative r such that s*s + r = k.
fn.expt(z1, z2)Returns z1 to the power z2.
fn["make-rectangular"](x, y)Returns the complex number x + iy.
fn["make-polar"](r, theta)Returns the complex number with magnitude r and angle theta.
fn["real-part"](z)Returns x such that z = x + iy.
fn["imag-part"](z)Returns y such that z = x + iy.
fn.magnitude(z)Returns the magnitude of z.
fn.angle(z)Returns fn.atan2(y,x) where z = x + iy.
fn["number->string"](z)Converts z to a string, base 10.
fn["number->string"](z, radix)Converts z to a string, base radix.
fn["number->string"](z, radix, precision)Converts and suffixes z with a count of significant bits.
fn["string->number"](string)Parses string as a Scheme number.
fn["string->number"](string, radix)Parses string as a Scheme number using radix as default radix.

SchemeNumber

A number object as defined by the Scheme language.

Scheme supports exact arithmetic and mixing exact with standard (inexact) numbers.  Several basic operations, including addition, subtraction, multiplication, and division, when given only exact arguments, must return an exact, numerically correct result.

These operations are allowed to fail due to running out of memory, but they are not allowed to return approximations the way ECMAScript operators may, unless given one or more inexact arguments.

For example, adding exact 1/100 to exact 0 one hundred times produces exactly 1, not 1.0000000000000007 as in JavaScript.  Raising exact 2 to the power of exact 1024 returns a 308-digit integer with complete precision, not Infinity as in ECMAScript.

This implementation provides all functions listed in the R6RS Scheme specification, Section 11.7, along with <eqv?> from Section 11.5.  (<eqv?> uses JavaScript’s *===* to compare non-numbers.)

Exact numbers support the standard ECMA Number formatting methods (toFixed, toExponential, and toPrecision) without a fixed upper limit to precision.

The schemeNumber.js file exports an object SchemeNumber.  It contains a property fn, which in turn contains the functions implementing the numeric types.

The SchemeNumber object is in fact a function that converts its argument to a Scheme number: similar to a constructor, but it may not always return an object, let alone a unique object.

Parameters

objObject to be converted to a Scheme number.

obj may have any of the following types:

Scheme numberreturned unchanged.
Stringconverted as if by string->number.
Native ECMAScript numbertreated as an inexact real.

Returns

A Scheme number.

Exceptions

If obj can not be parsed, SchemeNumber will raise an exception with condition type &assertion.

See Also

fn, raise, R6RS Chapter 3: Numbers

Summary
VERSIONLibrary version as an array of integers.
raiseFunction that translates a Scheme exception to ECMAScript.
maxIntegerDigitsMaximum size of integers created by the fn.expt(z1, z2) function.
toString(radix)Converts this Scheme number to a string.
toFixed(fractionDigits)Returns this Scheme number as a string with fractionDigits digits after the decimal point.
toExponential(fractionDigits)Converts this Scheme number to scientific "e" notation with fractionDigits digits after the decimal point.
toPrecision(precision)Converts this Scheme number to decimal (possibly "e" notation) with precision significant digits.
fnContainer of Scheme functions.
Function listAll Scheme functions are specified by R6RS.
Scheme functionsElements of fn.
fn["number?"](obj)Returns true if obj is a Scheme number.
fn["complex?"](obj)Returns true if obj is a Scheme complex number.
fn["real?"](obj)Returns true if obj is a Scheme real number.
fn["rational?"](obj)Returns true if obj is a Scheme rational number.
fn["integer?"](obj)Returns true if obj is a Scheme integer.
fn["real-valued?"](obj)Returns true if obj is a Scheme complex number and fn["imag-part"](obj) is zero.
fn["rational-valued?"](obj)Returns true if obj is real-valued and fn["real-part"](obj) is rational.
fn["integer-valued?"](obj)Returns true if obj is real-valued and fn["real-part"](obj) is an integer.
fn["exact?"](z)Returns true if z is exact.
fn["inexact?"](z)Returns true if z is inexact.
fn.inexact(z)Returns an inexact number equal to z.
fn.exact(z)Returns an exact number equal to z.
fn["eqv?"](obj1, obj2)Returns true if obj1 === obj2 or both arguments are Scheme numbers and behave identically.
fn["="](z, z, z...)Returns true if all arguments are mathematically equal, though perhaps differing in exactness.
fn["<"](x, x, x...)Returns true if arguments increase monotonically.
fn[">"](x, x, x...)Returns true if arguments decrease monotonically.
fn["<="](x, x, x...)Returns true if arguments are monotonically nondecreasing.
fn[">="](x, x, x...)Returns true if arguments are monotonically nonincreasing.
fn["zero?"](z)Returns true if z equals zero.
fn["positive?"](x)Returns true if x is positive.
fn["negative?"](x)Returns true if x is negative.
fn["odd?"](n)Returns true if n is odd.
fn["even?"](n)Returns true if n is even.
fn["finite?"](x)Returns true if x is finite.
fn["infinite?"](x)Returns true if x is plus or minus infinity.
fn["nan?"](x)Returns true if x is a NaN.
fn.max(x, x...)Returns the greatest argument.
fn.min(x, x...)Returns the least argument.
fn["+"](z...)Returns the sum of the arguments.
fn["*"](z...)Returns the product of the arguments.
fn["-"](z)Returns the negation of z (-z).
fn["-"](z1, z2...)Returns z1 minus the sum of the number(s) z2.
fn["/"](z)Returns the reciprocal of z (1 / z).
fn["/"](z1, z2...)Returns z1 divided by the product of the number(s) z2.
fn.abs(x)Returns the absolute value of x.
fn["div-and-mod"](x, y)Returns fn.div(x, y) and fn.mod(x, y).
fn.div(x, y)Returns the greatest integer less than or equal to x / y.
fn.mod(x, y)Returns x - (y * fn.div(x, y)).
fn["div0-and-mod0"](x, y)Returns fn.div0(x, y) and fn.mod0(x, y).
fn.div0(x, y)Returns the integer nearest x / y, ties go lower.
fn.mod0(x, y)Returns x - (y * fn.div0(x, y)).
fn.gcd(n...)Returns the arguments’ greatest common non-negative divisor.
fn.lcm(n...)Returns the arguments’ least common positive multiple.
fn.numerator(q)Returns q * fn.denominator(q).
fn.denominator(q)Returns the smallest positive integer which when multiplied by q yields an integer.
fn.floor(x)Returns the greatest integer not greater than x.
fn.ceiling(x)Returns the least integer not less than x.
fn.truncate(x)Returns the closest integer between 0 and x.
fn.round(x)Returns the closest integer to x, ties go even.
fn.rationalize(x, y)Returns the simplest fraction within y of x.
fn.exp(z)Returns e to the z.
fn.log(z)Returns the natural logarithm of z.
fn.log(z1, z2)Returns the base-z2 logarithm of z1.
fn.sin(z)Returns the sine of z.
fn.cos(z)Returns the cosine of z.
fn.tan(z)Returns the tangent of z.
fn.asin(z)Returns a number whose sine is z.
fn.acos(z)Returns a number whose cosine is z.
fn.atan(z)Returns a number whose tangent is z.
fn.atan(y, x)Returns the angle that passes through (x,y).
fn.sqrt(z)Returns the square root of z.
fn["exact-integer-sqrt"](k)Returns maximal exact s and non-negative r such that s*s + r = k.
fn.expt(z1, z2)Returns z1 to the power z2.
fn["make-rectangular"](x, y)Returns the complex number x + iy.
fn["make-polar"](r, theta)Returns the complex number with magnitude r and angle theta.
fn["real-part"](z)Returns x such that z = x + iy.
fn["imag-part"](z)Returns y such that z = x + iy.
fn.magnitude(z)Returns the magnitude of z.
fn.angle(z)Returns fn.atan2(y,x) where z = x + iy.
fn["number->string"](z)Converts z to a string, base 10.
fn["number->string"](z, radix)Converts z to a string, base radix.
fn["number->string"](z, radix, precision)Converts and suffixes z with a count of significant bits.
fn["string->number"](string)Parses string as a Scheme number.
fn["string->number"](string, radix)Parses string as a Scheme number using radix as default radix.

VERSION

Library version as an array of integers.

For example, [1,2,4] corresponds to Version 1.2.4.

raise

Function that translates a Scheme exception to ECMAScript.

When a library function encounters a situation where the Scheme specification requires it to raise an exception with a certain condition type, the function calls SchemeNumber.raise.

Programs may assign a custom function to SchemeNumber.raise to intercept such exceptions.

Parameters

conditionTypeThe specified condition, for example, "&assertion".
messageA string describing the error.
irritants...Zero or more erroneous data arguments.

Returns

The default SchemeNumber.raise function simply throws an Error.

See Also

fn, SchemeNumber

maxIntegerDigits

Maximum size of integers created by the fn.expt(z1, z2) function.

To avoid using up all system memory, exact results of a call to fn.expt(z1, z2) are capped at a configurable number of digits, by default one million.  SchemeNumber.maxIntegerDigits holds this limit.

The size limit does not currently protect against other means of creating large exact integers.  For example, when passed "#e1e9999999", the SchemeNumber function tries to allocate 10 million digits, regardless of maxIntegerDigits.

In a future release, cases such as the preceeding example may be checked.  If there is any possibility of legitimately creating such large integers, either as number objects or components thereof, code should increase maxIntegerDigits.

Default Value

  • 1000000 (1e6 or 1 million)

toString(radix)

Converts this Scheme number to a string.

The toString method converts inexact numbers as in JavaScript and exact numbers as if by fn["number->string"](z, radix).

toFixed(fractionDigits)

Returns this Scheme number as a string with fractionDigits digits after the decimal point.

Examples

SchemeNumber("#e1.2").toFixed(2)  // "1.20"
SchemeNumber("1/7").toFixed(24)   // "0.142857142857142857142857"

Specified by: ECMA-262, 5th edition

toExponential(fractionDigits)

Converts this Scheme number to scientific "e" notation with fractionDigits digits after the decimal point.

Examples

SchemeNumber("1/11").toExponential(3)  // "9.091e-2"
SchemeNumber("1/2").toExponential(2)   // "5.00e-1"

Specified by: ECMA-262, 5th edition

toPrecision(precision)

Converts this Scheme number to decimal (possibly "e" notation) with precision significant digits.

Examples

SchemeNumber("12300").toPrecision(2)  // "1.2e+4"
SchemeNumber("12300").toPrecision(4)  // "1.230e+4"
SchemeNumber("12300").toPrecision(5)  // "12300"
SchemeNumber("12300").toPrecision(6)  // "12300.0"

Specified by: ECMA-262, 5th edition

fn

Container of Scheme functions.

The SchemeNumber object contains a property, SchemeNumber.fn, which in turn contains the functions implementing the Scheme numeric types.

These functions are stored in fn under their Scheme names, so ["quotation"] is needed where the names contain characters that are incompatible with dot.notation.  (In JavaScript, X.Y and X["Y"] are equivalent expressions where Y is a valid identifier.  Not all Scheme function names are valid JavaScript identifiers, so one needs the second syntax to extract them from fn.)

You may find it convenient to copy SchemeNumber, fn, and the output function <number->string> into short-named variables, by convention sn, fn, and ns.  The rest of this section assumes you have done this:

var sn = SchemeNumber;
var fn = sn.fn;
var ns = fn["number->string"];

Functions that require a Scheme number argument automatically filter the argument through SchemeNumber.

For example, "2" (string) would be exact (parsed as Scheme) but 2 (equal to 2.0) would be inexact, as demonstrated:

a1 = fn["exact?"]("2");       // a1 === true
a1 = fn["exact?"](sn("2"));   // same

a2 = fn["exact?"](2);         // a2 === false
a2 = fn["exact?"]("2.0");     // same
a2 = fn["exact?"](sn("2.0")); // same

Note that the following functions accept arguments of any type and therefore do not apply SchemeNumber to their arguments:

  • <eqv?>
  • <number?>
  • <complex?>
  • <real?>
  • <rational?>
  • <integer?>
  • <real-valued?>
  • <rational-valued?>
  • <integer-valued?>

Here, for example, is 2 to the 1,024th power, as a decimal string:

a3 = ns(fn.expt("2", "1024"));

Fractional arithmetic:

a4 = fn["+"]("1/3", "4/5");  // 17/15

Numerator and denominator of a floating-point value, hexadecimal:

a5 = ns(fn.numerator(1/3), "16");    // "#i15555555555555"
a6 = ns(fn.denominator(1/3), "16");  // "#i40000000000000"

The #i prefix denotes an inexact number, as detailed in R6RS.  Since 1/3 is a native JavaScript number, the library regards it as inexact, and operations such as numerator yield inexact integer results.  If we used "1/3" (quoted) instead of 1/3, the numerator and denominator would be the mathematically correct 1 and 3.

Functions specified to return two values (such as <div-and-mod> and <exact-integer-sqrt>) return a two-element array as per JavaScript conventions.

Caveats

  • Arcane features such as explicit mantissa widths or complex transcendental functions, while believed complete, are unoptimized.
  • The library exhibits other visible behaviors besides those described herein.  However, they are not part of its public API and may change or disappear from one release to the next.
  • In particular, Scheme numbers’ toString property sometimes produces output that is incorrect in the Scheme sense.  (This stems from the decision to represent inexact reals as unadorned native numbers.)

To serialize numbers as Scheme would, use <SchemeNumber.fn["number->string"]>.

"" + SchemeNumber(2);                  // "2"
SchemeNumber.fn["number->string"](2);  // "2."

To test a Scheme number for numerical equality with another Scheme number or a native value, use <fn["="]>.  Likewise for <fn[">"]> etc.

See Also

Scheme functions

Function list

All Scheme functions are specified by R6RS.  In the list below, argument names indicate applicable types as follows:

objany value
zany Scheme number
xa real number
ya real number
qa rational number (excludes infinities and NaN)
nan integer
kan exact, non-negative integer
radixan exact integer, either 2, 8, 10, or 16
precisionan exact, positive integer

Scheme functions

Elements of fn.

Refer to the argument type key under Function list.

fn["number?"](obj)

Returns true if obj is a Scheme number.  Specified by: R6RS.

fn["complex?"](obj)

Returns true if obj is a Scheme complex number.  Specified by: R6RS.

fn["real?"](obj)

Returns true if obj is a Scheme real number.  Specified by: R6RS.

fn["rational?"](obj)

Returns true if obj is a Scheme rational number.  Specified by: R6RS.

fn["integer?"](obj)

Returns true if obj is a Scheme integer.  Specified by: R6RS.

fn["real-valued?"](obj)

Returns true if obj is a Scheme complex number and fn["imag-part"](obj) is zero.  Specified by: R6RS.

fn["rational-valued?"](obj)

Returns true if obj is real-valued and fn["real-part"](obj) is rational.  Specified by: R6RS.

fn["integer-valued?"](obj)

Returns true if obj is real-valued and fn["real-part"](obj) is an integer.  Specified by: R6RS.

fn["exact?"](z)

Returns true if z is exact.  Specified by: R6RS.

fn["inexact?"](z)

Returns true if z is inexact.  Specified by: R6RS.

fn.inexact(z)

Returns an inexact number equal to z.  Specified by: R6RS.

fn.exact(z)

Returns an exact number equal to z.  Specified by: R6RS.

fn["eqv?"](obj1, obj2)

Returns true if obj1 === obj2 or both arguments are Scheme numbers and behave identically.  Specified by R6RS.

fn["="](z, z, z...)

Returns true if all arguments are mathematically equal, though perhaps differing in exactness.  Specified by: R6RS.

fn["<"](x, x, x...)

Returns true if arguments increase monotonically.  Specified by: R6RS.

fn[">"](x, x, x...)

Returns true if arguments decrease monotonically.  Specified by: R6RS.

fn["<="](x, x, x...)

Returns true if arguments are monotonically nondecreasing.  Specified by: R6RS.

fn[">="](x, x, x...)

Returns true if arguments are monotonically nonincreasing.  Specified by: R6RS.

fn["zero?"](z)

Returns true if z equals zero.  Specified by: R6RS.

fn["positive?"](x)

Returns true if x is positive.  Specified by: R6RS.

fn["negative?"](x)

Returns true if x is negative.  Specified by: R6RS.

fn["odd?"](n)

Returns true if n is odd.  Specified by: R6RS.

fn["even?"](n)

Returns true if n is even.  Specified by: R6RS.

fn["finite?"](x)

Returns true if x is finite.  Specified by: R6RS.

fn["infinite?"](x)

Returns true if x is plus or minus infinity.  Specified by: R6RS.

fn["nan?"](x)

Returns true if x is a NaN.  Specified by: R6RS.

fn.max(x, x...)

Returns the greatest argument.  Specified by: R6RS.

fn.min(x, x...)

Returns the least argument.  Specified by: R6RS.

fn["+"](z...)

Returns the sum of the arguments.  Specified by: R6RS.

fn["*"](z...)

Returns the product of the arguments.  Specified by: R6RS.

fn["-"](z)

Returns the negation of z (-z).  Specified by: R6RS.

fn["-"](z1, z2...)

Returns z1 minus the sum of the number(s) z2.  Specified by: R6RS.

fn["/"](z)

Returns the reciprocal of z (1 / z).  Specified by: R6RS.

fn["/"](z1, z2...)

Returns z1 divided by the product of the number(s) z2.  Specified by: R6RS.

fn.abs(x)

Returns the absolute value of x.  Specified by: R6RS.

fn["div-and-mod"](x, y)

Returns fn.div(x, y) and fn.mod(x, y).  Specified by: R6RS.

fn.div(x, y)

Returns the greatest integer less than or equal to x / y.  Specified by: R6RS.

fn.mod(x, y)

Returns x - (y * fn.div(x, y)).  Specified by: R6RS.

fn["div0-and-mod0"](x, y)

Returns fn.div0(x, y) and fn.mod0(x, y).  Specified by: R6RS.

fn.div0(x, y)

Returns the integer nearest x / y, ties go lower.  Specified by: R6RS.

fn.mod0(x, y)

Returns x - (y * fn.div0(x, y)).  Specified by: R6RS.

fn.gcd(n...)

Returns the arguments’ greatest common non-negative divisor.  Specified by: R6RS.

fn.lcm(n...)

Returns the arguments’ least common positive multiple.  Specified by: R6RS.

fn.numerator(q)

Returns q * fn.denominator(q).  Specified by: R6RS.

fn.denominator(q)

Returns the smallest positive integer which when multiplied by q yields an integer.  Specified by: R6RS.

fn.floor(x)

Returns the greatest integer not greater than x.  Specified by: R6RS.

fn.ceiling(x)

Returns the least integer not less than x.  Specified by: R6RS.

fn.truncate(x)

Returns the closest integer between 0 and x.  Specified by: R6RS.

fn.round(x)

Returns the closest integer to x, ties go even.  Specified by: R6RS.

fn.rationalize(x, y)

Returns the simplest fraction within y of x.  Specified by: R6RS.

fn.exp(z)

Returns e to the z.  Specified by: R6RS.

fn.log(z)

Returns the natural logarithm of z.  Specified by: R6RS.

fn.log(z1, z2)

Returns the base-z2 logarithm of z1.  Specified by: R6RS.

fn.sin(z)

Returns the sine of z.  Specified by: R6RS.

fn.cos(z)

Returns the cosine of z.  Specified by: R6RS.

fn.tan(z)

Returns the tangent of z.  Specified by: R6RS.

fn.asin(z)

Returns a number whose sine is z.  Specified by: R6RS.

fn.acos(z)

Returns a number whose cosine is z.  Specified by: R6RS.

fn.atan(z)

Returns a number whose tangent is z.  Specified by: R6RS.

fn.atan(y, x)

Returns the angle that passes through (x,y).  Specified by: R6RS.

fn.sqrt(z)

Returns the square root of z.  Specified by: R6RS.

fn["exact-integer-sqrt"](k)

Returns maximal exact s and non-negative r such that s*s + r = k.  Specified by: R6RS.

fn.expt(z1, z2)

Returns z1 to the power z2.  Specified by: R6RS.

fn["make-rectangular"](x, y)

Returns the complex number x + iy.  Specified by: R6RS.

fn["make-polar"](r, theta)

Returns the complex number with magnitude r and angle theta.  Specified by: R6RS.

fn["real-part"](z)

Returns x such that z = x + iy.  Specified by: R6RS.

fn["imag-part"](z)

Returns y such that z = x + iy.  Specified by: R6RS.

fn.magnitude(z)

Returns the magnitude of z.  Specified by: R6RS.

fn.angle(z)

Returns fn.atan2(y,x) where z = x + iy.  Specified by: R6RS.

fn["number->string"](z)

Converts z to a string, base 10.

For exact z, number->string retains full precision.  Exact fractions are expressed as numerator + "/" + denominator.  Examples:

fn["number->string"](fn["string->number"]("#e1.2"))  // "6/5"
fn["number->string"](fn["/"]("12", "-8"))            // "-3/2"

Infinities are "+inf.0" and "-inf.0".  NaN is "+nan.0".

The result always yields a number equal to z (in the sense of <fn["eqv?"](obj1, obj2)>) when passed to fn["string->number"](string).

Specified by: R6RS

See Also: fn["string->number"](string).

fn["number->string"](z, radix)

Converts z to a string, base radixradix must be exact 2, 8, 10, or 16.

The output never contains an explicit radix prefix.

The result always yields a value equal to z (in the sense of <fn["eqv?"](obj1, obj2)>) when converted back to a number by fn["string->number"](string, radix).

Specified by: R6RS

See Also: fn["string->number"](string, radix).

fn["number->string"](z, radix, precision)

Converts and suffixes z with a count of significant bits.

Appends "|p" to each inexact real component of z where p is the smallest mantissa width not less than precision needed to represent the component exactly.

Specified by: R6RS

fn["string->number"](string)

Parses string as a Scheme number.  Returns false if unable.

Examples

"1"       - exact 1.
"1."      - inexact 1, same as "1.0".
"1/2"     - exact one-half, same as "2/4" etc.
"0.5"     - inexact 0.5.
"12e3"    - inexact 12000.
"i"       - the imaginary unit.
"-2+1/2i" - exact complex number.
"2.@1"    - complex in polar coordinates, r=2.0, theta=1.0.
"+inf.0"  - positive infinity.
"-inf.0"  - negative infinity.
"+nan.0"  - IEEE NaN (not-a-number).
"#e0.5"   - exact one-half, forced exact by prefix #e.
"#i1/2"   - 0.5, inexact by prefix #i.
"#x22"    - exact 34; prefix #x hexadecimal.
"#o177"   - exact 127; prefix #o octal.
"#b101"   - exact 5; prefix #b binary.
"#i#b101" - inexact 5.0.
"#b#i101" - same.
"1.2345678|24" - rounded as if to single-precision (about 1.23456776).

Specified by: R6RS

See Also: fn["number->string"](z), R6RS section 4.2.8: Lexical syntax: Numbers

fn["string->number"](string, radix)

Parses string as a Scheme number using radix as default radix.

radix must be exact 2, 8, 10, or 16.  If string contains a radix prefix, the prefix takes precedence over radix.

Specified by: R6RS

See Also: fn["number->string"](z, radix).

A number object as defined by the Scheme language.
Returns z1 to the power z2.
Elements of fn.
Container of Scheme functions.
BigInteger
An arbitrarily-large integer.
Function that translates a Scheme exception to ECMAScript.
Maximum size of integers created by the fn.expt(z1, z2) function.
Converts z to a string, base radix.
All Scheme functions are specified by R6RS.
Parses string as a Scheme number.
Parses string as a Scheme number using radix as default radix.
Converts z to a string, base 10.
Close