|
This part of the guide contains detailed descriptions of the
BUSH built-in packages.
4.7 Numerics Package
The BUSH built-in package numerics provides mathematical functions for
floating point numbers. Most of the functions accept any kind of number.
The bit shifting operations which require a natural for the number of bits
to shift, and leading_part requires an integer as the second parameter.
GCC Ada Equivalent: numerics combines several Ada.Numerics child
packages and type attributes
Predefined numeric constants:
-
numerics.e
-
numerics.log2_e
-
numerics.log10_e
-
numerics.ln10 - log e 10
-
numerics.ln2 - log e 2
-
numerics.pi
-
numerics.pi_by_2 - pi / 2
-
numerics.pi_by_4 - pi / 4
-
numerics.pi_under_1 - 1 / pi
-
numerics.pi_under_2 - 2 / pi
-
numerics.sqrt_pi_under_2 - 2 / sqrt( pi ) )
-
numerics.sqrt_2 - sqrt( 2 )
-
numerics.sqrt_2_under_1 - 1 / sqrt(2)
Absolute value (abs) is not technically a part of the numerics package
but is documented here.
f := abs( e )
return the absolute value of e
Example: f := abs( e );
Ada Equivalent: built-in abs function
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the absolute value of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.arcsin( e [,cycle] )
trig arcsin function
Example: f := arcsin( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arcsin
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the arcsin of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f := numerics.arcsinh( e )
trig arcsinh function
Example: f := arcsinh( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arcsinh
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the arcsinh value of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.arctan( x, y [,cycle] )
trig arctan function
Example: f := numerics.arctan( x, y );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arctan
Parameters:
x,y |
in |
universal_numeric |
required |
the expressions to to take the arctan of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f := numerics.arctanh( e )
trig arctanh function
Example: f := arctanh( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arctanh
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the arctanh of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.arccos( e [,cycle] )
trig arccos function
Example: f := numerics.arccos( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arccos
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the arccos of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f := numerics.arccosh( e )
trig arccosh function
Example: f := arccosh( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arccosh
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the arccosh of |
f |
return value |
universal_numeric |
required |
the result |
|
numerics.arccot( x, y [,cycle] )
trig arccot function
Example: f := numerics.arccot( x, y );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arccot
Parameters:
x,y |
in |
universal_numeric |
required |
the expressions to to take the arccot of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f := numerics.arccoth( e )
trig arccoth function
Example: f := arccoth( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.arccoth
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the arccoth of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.ceiling( e )
truncate decimal part, round up
Example: f := ceiling( 5.5 );
Ada Equivalent: 'ceiling attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the ceiling of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.copy_sign( x, y )
return float x with sign of float y
Example: f := numerics.copy_sign( 5.5, -1.0 );
Ada Equivalent: 'copy_sign attribute
Parameters:
x |
in |
universal_numeric |
required |
the expression to take the absolute value of |
y |
in |
universal_numeric |
required |
the expression to take the sign of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.cos( e [,cycle] )
trig cosine function
Example: f := numerics.cos( numerics.pi );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.cos
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the cosine of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f :=numerics.cosh( x )
trig cosh functionExample: f := cosh( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.cosh
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the cosh of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.cot( e [,cycle] )
trig cotangent function
Example: f := numerics.cot( numerics.pi );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.cos
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the cotangent of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f := numerics.coth( e )
trig coth function
Example: f := coth( numerics.pi );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.coth
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the coth of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.even( x )
even function
Example: f := numerics.even( 2 ); -- true
Ada Equivalent: N/A ( x mod 2 = 0 )
Parameters:
x |
in |
integer |
required |
the value to test |
f |
return value |
boolean |
required |
true if integer is even |
|
f := numerics.exp( x )
exp function
Example: f := exp( 1.0 );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.exp
Parameters:
e |
in |
universal_numeric |
required |
the power to raise epsilon to |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.exponent( x )
Ada's exponent attribute
Example: f := numerics.exponent( 10.0 ); -- returns 4
Ada Equivalent: 'exponent attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.floor( x )
truncate decimal part, round down
Example: f := numerics.floor( 5.5 );
Ada Equivalent: 'floor attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression to take the floor of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.fraction( x )
Ada's fraction attribute
Example: f := numerics.fraction( 10.0 ); -- returns 0.625
Ada Equivalent: 'fraction attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.leading_part( x, y )
Ada's leading part attribute (not quite sure what this does)
Example: f := numerics.leading_part( x, y );
Ada Equivalent: 'leading_part attribute
Parameters:
x,y |
in |
universal_numeric |
required |
the expressions |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.log( e [,base] )
log function
Example: f := numerics.log( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.log
Parameters:
e |
in |
universal_numeric |
required |
the expressions to take the log of |
base |
in |
universal_numeric |
10 (I think) |
the base of the log |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.machine( x )
Ada's machine attribute (not sure what this does)
Example: f := numerics.machine( 10.0 ); -- returns 10.0
Ada Equivalent: 'machine attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.max( x, y )
return the larger of x and y
Example: f := numerics.max( 1.0, 2.0 );
Ada Equivalent: 'max attribute
Parameters:
x,y |
in |
universal_numeric |
required |
the expressions to be compared |
f |
return value |
universal_numeric |
required |
the result |
|
r := numerics.md5( s )
return the message digest 5 fingerprint of string s
Example: sig := numerics.md5( "Checksum for this message" );
Ada Equivalent: none, uses MD5 package (www.AdaPower.com)
Parameters:
s |
in |
string |
required |
the string to generate an MD5 checksum for |
r |
return value |
string |
required |
the MD5 checksum |
|
f := numerics.min( x, y )
return the smaller of x and y
Example: f := numerics.max( 1.0, 2.0 );
Ada Equivalent: 'min attribute
Parameters:
x,y |
in |
universal_numeric |
required |
the expressions to be compared |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.odd( x )
odd function
Example: f := numerics.odd( 1 ); -- true
Ada Equivalent: N/A ( x mod 2 = 1 )
Parameters:
x |
in |
integer |
required |
the value to test |
f |
return value |
boolean |
required |
true if integer is odd |
|
p := numerics.pos( c )
return the ASCII value (position) of character c
Example: p := numerics.pos( 'a' ); -- returns 97
Ada Equivalent: 'pos attribute
Restrictions: pos of enumerated types not supported
Parameters:
e |
in |
character |
required |
the expression to take the position of |
p |
return value |
positive |
required |
the position |
|
f := numerics.random
generate a random floating-point number between zero and one
Example: i := integer( numerics.truncation( numerics.random * 10 )+1
) ); -- returns 1 to 10
Ada Equivalent: Ada.Numerics.Float_Random.Random
Parameters:
f |
return value |
float |
required |
the random number |
|
r := numerics.rnd( p )
generate a random positive number between 1 and p
Example: r := numerics.rnd( 10 ); -- 1 to 10
Ada Equivalent: none (BUSH extension)
Parameters:
p |
in |
positive |
required |
the maximum positive number to return |
r |
return value |
positive |
required |
the random number |
|
i := numerics.rotate_left( e, b )
rotate expression e up to 64 bits left by natural b bits
Example: p := numerics.rotate_left( 16, 2 );
Ada Equivalent: Interfaces.Rotate_Left
Parameters:
e |
in |
universal_numeric |
required |
the expression to rotate |
b |
in |
natural |
required |
the number of bits to rotate |
p |
return value |
universal_numeric |
required |
the result |
|
i := numerics.rotate_right( e, b )
rotate expression e up to 64 bits right by natural b bits
Example: f := numerics.rotate_right( 16, 2 );
Ada Equivalent: Interfaces.Rotate_Right
Parameters:
e |
in |
universal_numeric |
required |
the expression to rotate |
b |
in |
natural |
required |
the number of bits to rotate |
p |
return value |
universal_numeric |
required |
the result |
|
f := numerics.remainder( x, y )
remainder of a floating point divide of x by y
Example: f := numerics.remainder( 16.5, 2.0 );
Ada Equivalent: 'remainder attribute
Parameters:
x |
in |
universal_numeric |
required |
the expression to divide |
y |
in |
universal_numeric |
required |
the amount to divide by |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.rounding( e )
truncate decimal part, round to nearest. Round up on .5
Example: f := numerics.rounding( 5.5 );
Ada Equivalent: 'rounding attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression to round |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.scaling( x, y )
multiply floating point number by 2 to the power of integer y
Example: f := numerics.scaling( 5.5, 3 );
Ada Equivalent: 'scaling attribute
Parameters:
x |
in |
universal_numeric |
required |
the expression to round |
y |
in |
integer |
required |
the power to scale by |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.serial
return a natural integer, unique to this session. That is, the first
invocation returns zero, the second returns one and so forth. The number
returns to zero when it exceeds System.Max_Integer.
Example: f := numerics.serial;
Ada Equivalent: none (BUSH extension)
Parameters:
f |
return value |
natural |
required |
the serial number result |
|
i := numerics.shift_left( e, b )
shift expression e up to 64 bits left by natural b bits
Example: f := numerics.shift_left( 16, 2 );
Ada Equivalent: Interfaces.Shift_Left
Parameters:
e |
in |
universal_numeric |
required |
the expression to shift |
b |
in |
natural |
required |
the number of bits to shift |
i |
return value |
universal_numeric |
required |
the result |
|
i := numerics.shift_right( e, b )
shift expression e up to 64 bits right by natural b bits
Example: f := numerics.shift_right( 16, 2 );
Ada Equivalent: Interfaces.Shift_Right
Parameters:
e |
in |
universal_numeric |
required |
the expression to shift |
b |
in |
natural |
required |
the number of bits to shift |
i |
return value |
universal_numeric |
required |
the result |
|
i := numerics.shift_right_arithmetic( e, b )
shift expression e up to 64 bits right by natural b bits, preserving
sign
Example: f := numerics.shift_right_arithmetic( 16, 2 );
Ada Equivalent: Interfaces.Shift_Right_Arithmetic
Parameters:
e |
in |
universal_numeric |
required |
the expression to shift |
b |
in |
natural |
required |
the number of bits to shift |
i |
return value |
universal_numeric |
required |
the result |
|
f := numerics.sin( e [,cycle] )
trig sine function
Example: f := numerics.sin( numerics.pi );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.sin
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the sine of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f := numerics.sinh( e )
trig sinh function
Example: f := numerics.sinh( numerics.pi );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.sinh
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the sinh of |
f |
return value |
floating point |
required |
the result |
|
f := numerics.sqrt( e )
square root of e
Example: f := numerics.sqrt( 9.0 );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.sqrt
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the square root of |
f |
return value |
floating point |
required |
the result |
|
f := numerics.sturges( l, h, t );
Sturge's method: compute a grouping size for data with a low value
of l, high value of h, and a sum total of t
Example: f := numerics.sturges( 18, 64, 421 );
Ada Equivalent: none (AdaScript extension)
Parameters:
l |
in |
universal_numeric |
required |
the lowest value |
h |
in |
universal_numeric |
required |
the highest value |
t |
in |
universal_numeric |
required |
the sum total |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.tan( e [,cycle] )
trig tangent function
Example: f := numerics.tan( numerics.pi );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.tan
Parameters:
e |
in |
universal_numeric |
required |
the expressions to to take the tangent of |
cycle |
in |
universal_numeric |
numerics.pi*2 |
the trig period (eg. 360 for degrees), default is radians |
f |
return value |
floating point |
required |
the result |
|
f :=numerics.tanh( e )
trig tanh function
Example: f := tanh( e );
Ada Equivalent: Ada.Numerics.Generic_Elementary_Functions.tanh
Parameters:
e |
in |
universal_numeric |
required |
the expression to to take the tanh of |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.truncation( e )
truncate decimal part
Example: f := numerics.truncation( 5.5 );
Ada Equivalent: 'truncation attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression to truncate |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.unbiased_rounding( e )
round to nearest even number if exactly between two integers. That
is, 5.5 will round up to 6 and 6.5 will round down to 6.
Example: f := numerics.unbiased_rounding( 5.5 );
Ada Equivalent: 'unbiased_rounding attribute
Parameters:
e |
in |
universal_numeric |
required |
the expression to round |
f |
return value |
universal_numeric |
required |
the result |
|
f := numerics.value( s )
convert string s to a numeric value (inverse of strings.image). If
the number is positive, the string must begin with a space or an exception
will be raised.
Example: f := numerics.value( " 32.5" ) * numerics.value( "-1.2" );
Ada Equivalent: 'value attribute
Parameters:
s |
in |
universal_string |
required |
the expression to convert to a number. |
f |
return value |
universal_numeric |
required |
the result |
|
Back to Top
|