Floating-slash routines


Functions

void build (flash x, int(*gen)(_MIPT_ big, int))
void dconv (double d, flash w)
void denom (flash x, big y)
void facos (flash x, flash y)
void facosh (flash x, flash y)
void fadd (flash x, flash y, flash z)
void fasin (flash x, flash y)
void fasinh (flash x, flash y)
void fatan (flash x, flash y)
void fatanh (flash x, flash y)
int fcomp (flash x, flash y)
void fconv (int n, int d, flash x)
void fcos (flash x, flash y)
void fcosh (flash x, flash y)
void fdiv (flash x, flash y, flash z)
double fdsize (flash w)
void fexp (flash x, flash y)
void fincr (flash x, int n, int d, flash y)
void flog (flash x, flash y)
void flop (flash x, flash y, int *op, flash z)
void fmodulo (flash x, flash y, flash z)
void fmul (flash x, flash y, flash z)
void fpack (big n, big d, flash x)
void fpi (flash pi)
void fpmul (flash x, int n, int d, flash y)
void fpower (flash x, int n, flash w)
void fpowf (flash x, flash y, flash z)
void frand (flash x)
void frecip (flash x, flash y)
BOOL froot (flash x, int n, flash w)
void fsin (flash x, flash y)
void fsinh (flash x, flash y)
void fsub (flash x, flash y, flash z)
void ftan (flash x, flash y)
void ftanh (flash x, flash y)
void ftrunc (flash x, big y, flash z)
void mround (big num, big den, flash z)
void numer (flash x, big y)

Function Documentation

void build ( flash  x,
int(*)(_MIPT_ big, int)  gen 
)

Uses supplied generator of regular continued fraction expansion to build up a flash number x, rounded if necessary

Parameters:
[out] x The flash number created
[in] gen The generator function
Example:
int phi(flash w, int n)
{
  // rcf generator for golden ratio //
  return 1;
}
...
build(x, phi);
...
// This will calculate the golden ratio (1 + sqrt(5)) / 2 in x -- very quickly!

void dconv ( double  d,
flash  w 
)

Converts a double to flash format

Parameters:
[in] d 
[out] w The flash equivalent of d

void denom ( flash  x,
big  y 
)

Extracts the denominator of a flash number

Parameters:
[in] x 
[out] y The denominator of x

void facos ( flash  x,
flash  y 
)

Calculates arc-cosine of a flash number, using fasin()

Parameters:
[in] x 
[out] y = arccos(x)
Precondition:
|x| must be less than or equal to 1

void facosh ( flash  x,
flash  y 
)

Calculates hyperbolic arc-cosine of a flash number

Parameters:
[in] x 
[out] y = arccosh(x)
Precondition:
|x| must be greater than or equal to 1

void fadd ( flash  x,
flash  y,
flash  z 
)

Adds two flash numbers

Parameters:
[in] x 
[in] y 
[out] z = $ x + y $

void fasin ( flash  x,
flash  y 
)

Calculates arc-sin of a flash number, using fatan()

Parameters:
[in] x 
[out] y = arcsin(x)
Precondition:
|x| must be less than or equal to 1

void fasinh ( flash  x,
flash  y 
)

Calculates hyperbolic arc-sin of a flash number

Parameters:
[in] x 
[out] y = arcsinh(x)

void fatan ( flash  x,
flash  y 
)

Calculates the arc-tangent of a flash number, using an $ O(n^{2.5}) $ method based on Newton's iteration

Parameters:
[in] x 
[out] y = arctan(x)

void fatanh ( flash  x,
flash  y 
)

Calculates the hyperbolic arc-tangent of a flash number

Parameters:
[in] x 
[out] y = arctanh(x)
Precondition:
$ x^2 $ must be less than 1

int fcomp ( flash  x,
flash  y 
)

Compares two flash numbers

Parameters:
[in] x 
[in] y 
Returns:
-1 if y > x, +1 if x > y and 0 if x = y

void fconv ( int  n,
int  d,
flash  x 
)

Converts a simple fraction to flash format

Parameters:
[in] n 
[in] d 
[out] x = $ n/d $

void fcos ( flash  x,
flash  y 
)

Calculates cosine of a given flash angle, using ftan()

Parameters:
[in] x 
[out] y = cos(x)

void fcosh ( flash  x,
flash  y 
)

Calculates hyperbolic cosine of a given flash angle

Parameters:
[in] x 
[out] y = cosh(x)

void fdiv ( flash  x,
flash  y,
flash  z 
)

Divides two flash numbers

Parameters:
[in] x 
[in] y 
[out] z = $ x / y $

double fdsize ( flash  w  ) 

Converts a flash number to double format

Parameters:
[in] w 
Returns:
The value of the parameter x as a double
Precondition:
The value of x must be representable as a double

void fexp ( flash  x,
flash  y 
)

Calculates the exponential of a flash number using $ O(n^{2.5}) $ method

Parameters:
[in] x 
[out] y = $ e^x $

void fincr ( flash  x,
int  n,
int  d,
flash  y 
)

Add a simple fraction to a flash number

Parameters:
[in] x 
[in] n 
[in] d 
[out] y = $ x + n/d $
Example:
// This subtracts two-thirds from the value of x
fincr(x, -2, 3, x);

void flog ( flash  x,
flash  y 
)

Calculates the natural log of a flash number using $ O(n^{2.5}) $ method

Parameters:
[in] x 
[out] y = log(x)

void flop ( flash  x,
flash  y,
int *  op,
flash  z 
)

Performs primitive flash operation. Used internally. See source listing comments for more details

Parameters:
[in] x 
[in] y 
[in] op 
[out] z = Fn(x,y), where the function performed depends on the parameter op

void fmodulo ( flash  x,
flash  y,
flash  z 
)

Finds the remainder when one flash number is divided by another

Parameters:
[in] x 
[in] y 
[out] z = $ x \pmod{y} $

void fmul ( flash  x,
flash  y,
flash  z 
)

Multiplies two flash numbers

Parameters:
[in] x 
[in] y 
[out] z = xy

void fpack ( big  n,
big  d,
flash  x 
)

Forms a flash number from big numerator and denominator

Parameters:
[in] n 
[in] d 
[out] x = $ n/d $
Precondition:
The denominator must be non-zero. Flash variable x and big variable d must be distinct. The resulting flash variable must not be too big for the representation

void fpi ( flash  pi  ) 

Calculates $\pi$ using Gauss-Legendre $ O(n^2 \log{n}) $ method. Note that on subsequent calls to this routine, $\pi$ is immediately available, as it is stored internally. (This routine is disappointingly slow. There appears to be no simple way to calculate a rational approximation to $\pi$ quickly)

Parameters:
[out] pi = $\pi$
Note:
Internally allocated memory is freed when the current MIRACL instance is ended by a call to mirexit()

void fpmul ( flash  x,
int  n,
int  d,
flash  y 
)

Multiplies a flash number by a simple fraction

Parameters:
[in] x 
[in] n 
[in] d 
[out] y = $ xn/d $

void fpower ( flash  x,
int  n,
flash  w 
)

Raises a flash number to an integer power

Parameters:
[in] x 
[in] n 
[out] w = $ x^n $

void fpowf ( flash  x,
flash  y,
flash  z 
)

Raises a flash number to a flash power

Parameters:
[in] x 
[in] y 
[out] z = $ x^y $

void frand ( flash  x  ) 

Generates a random flash number

Parameters:
[out] x A flash random number in the range 0 < x < 1

void frecip ( flash  x,
flash  y 
)

Calculates reciprocal of a flash number

Parameters:
[in] x 
[out] y = $ 1/x $

BOOL froot ( flash  x,
int  n,
flash  w 
)

Calculates n-th root of a flash number using Newton's $ O(n^2) $ method

Parameters:
[in] x 
[in] n 
[out] w = $ \sqrt[n]{x} $
Returns:
TRUE for exact root, otherwise FALSE

void fsin ( flash  x,
flash  y 
)

Calculates sine of a given flash angle. Uses ftan()

Parameters:
[in] x 
[out] y = sin(x)

void fsinh ( flash  x,
flash  y 
)

Calculates hyperbolic sine of a given flash angle

Parameters:
[in] x 
[out] y = sinh(x)

void fsub ( flash  x,
flash  y,
flash  z 
)

Subtracts two flash numbers

Parameters:
[in] x 
[in] y 
[out] z = $ x - y $

void ftan ( flash  x,
flash  y 
)

Calculates the tan of a given flash angle, using an $ O(n^{2.5}) $ method

Parameters:
[in] x 
[out] y = tan(x)

void ftanh ( flash  x,
flash  y 
)

Calculates the hyperbolic tan of a given flash angle

Parameters:
[in] x 
[out] y = tanh(x)

void ftrunc ( flash  x,
big  y,
flash  z 
)

Separates a flash number to a big number and a flash remainder

Parameters:
[in] x 
[out] y = int(x)
[out] z The fractional remainder. If y is the same as z, only int(x) is returned

void mround ( big  num,
big  den,
flash  z 
)

Forms a rounded flash number from big numerator and denominator. If rounding takes place the instance variable EXACT is set to FALSE. EXACT Is initialised to TRUE in routine mirsys(). This routine is used internally

Parameters:
[in] num 
[in] den 
[out] z = $ R(num/dem) $ --- the flash number $ num/dem $ is rounded if necessary to fit the representation
Precondition:
The denominator must be non-zero

void numer ( flash  x,
big  y 
)

Extracts the numerator of a flash number

Parameters:
[in] x 
[out] y the numerator of x