An infinite-precision calculator and function library for Miranda
Input syntax for Miranda version
(The Haskell version just creates a new type BigFloat, to which all the usual operations apply)
- The bignum version of zero
- The bignum version of one
- The bignum version of two
- bn_pi_2, bn_pi_4 and bn_2_pi
- pi/2, pi/4 and twice pi
Functions taking a single parameter
- takes a character string containing a decimal number and converts it to a bignum.
The string can have an arbitrary number of decimal places after the decimal point.
- takes an integer and converts it to a bignum (Note: an integer, not a floating point value, nor the result of a floating point calculation. You can try converting those using "bn (show x)", or more simply with the compound function "(bn.show), but entirely at your own risk!)
- is the inverse function of bn. It converts a bignum to a printable form.
Miranda calls this function automatically whenever it has to display a bignum.
- doubles its parameter (faster than "bn_times 2 x")
- halves its parameter (faster than "bn_quot x 2")
- returns the square of its argument (faster than "bn_mul x x")
- returns the square root of its argument
- negates its argument
- takes a positive integer seed as its parameter and returns a
pseudo-random bignum in the range 0 <= n < 1
Functions taking two parameters
- takes two bignum parameters and returns their sum.
- subtracts its second bignum parameter from its first, returning the difference.
- takes an integer and a bignum and returns their bignum product.
The integer is the first of the two parameters, so as to ease partial parameterisazion.
- multiplies two bignums
- divides a bignum by an positive integer.
If you want to partially parameterise the integer divisor, use "($bn_quot n)".
- performs long division of two bignums
- takes a bignum and an integer and returns the bignum raised to that integral power
- takes two bignums and returns the first raised to the power of the second
All these take and return one bignum. All angles are expressed in radians.
- returns the natural logarithm (in base e) of its parameter
- returns the inverse natural logarithm of its parameter
- returns the sine of its parameter.
It is fastest for values between -pi/2 and +pi/2
- returns the cosine of its parameter (defined using sin).
- returns the tangent of its parameter (defined using sin/cos).
- returns the arcsine (in the range -pi/2 to pi/2) of its parameter
(defined using atan)
- returns the arccosine (in the range -pi/2 to pi/2) of its parameter
(defined using atan)
- returns the arctangent (in the range -pi/2 to pi/2) of its parameter.
- bn_sinh, bn_cosh, bn_tanh,
bn_asinh, bn_acosh, bn_atanh
- return hyperbolic sine, cosine and tangent and their inverses.
For the convenience of Miranda programmers who wish
to use the bignum library as part of a larger program,
there is also a set of comparison functions
of little use in desk-calculator mode:
- tells you whether a bignum is zero.
- tells you whether a bignum has a negative value.
- compares two bignums and returns:
0 if the two numbers have the same value,
1 if the first number is greater than the second
-1 if the second number is greater than the first.
- bn_eq, bn_ne,
- The six usual comparison functions,
equal to, not equal to, greater than, less than,
greater than or equal to, less than or equal to.
They all take two bignum parameters and return a boolean value.
Note that, since functions are "greedy" to bind to their parameters,
brackets are necessary to make "5" the parameter to "bn",
rather than "bn" being taken as the first parameter to
"bn_sqrt" (which would make no sense).
- bn_sqrt bn_2
- The square root of two.
- bn_raise ( bn_mul (bn "1.5") (bn "0.75") ) 6
- The interval obtained by tuning up by a perfect fifth and down
by a perfect fourth, six times (not quite an octave!)
- bn_quot (bn_add bn_1 (bn_sqrt (bn "5"))) 2
- The golden ratio, calculated as (1 + sqrt(5)) / 2
Martin Guy <firstname.lastname@example.org>
Last modified: 2 January 2006