[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

Numerics Package

The SparForte built-in numerics package provides math subprograms to manipulate numeric values.

Functions with a universal_numeric parameter accept any kind of number (such as float, integer, etc.). 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)

The Ada complex number functions are not fully implemented.

Absolute value (abs) is not technically a part of the numerics package (it's a language construct) but is documented here.

f := abs( e )

 

return the absolute value of e

Example

f := abs( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the absolute value of
f return value universal_numeric required the result

Exceptions

-

See Also

-

Compare With

Ada: built-in abs function
PHP: abs
Python: abs/fabs

f := numerics.arccos( e [,cycle] )

 

trig inverse consine function

Example

f := numerics.arccos( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expressions 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

Exceptions

an argument_error if the absolute value of e exceeds 1

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arccos
PHP: acos
Python: acos

f := numerics.arccosh( e )

 

trig inverse hyperbolic cosine function

Example

f := arccosh( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the arccosh of
f return value universal_numeric required the result

Exceptions

an argument_error when e is less than 1

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arccosh
PHP: acosh

f := numerics.arccot( x, y [,cycle] )

 

trig inverse cotangent function

Example

f := numerics.arccot( x, y );

Parameters

Param Mode Type Default Description
x,y in universal_numeric required the expressions 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

Exceptions

an argument_error when x and y are both zero

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arccot (In Ada, the y parameter is optional.)

f := numerics.arccoth( e )

 

trig inverse hyperbolic cotangent function

Example

f := arccoth( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the arccoth of
f return value universal_numeric required the result

Exceptions

an argument_error when the absolute value of e is less than 1
a constraint_error when the absolute value of e is 1

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arccoth

f := numerics.arcsin( e [,cycle] )

 

trig inverse sine function

Example

f := arcsin( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression 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

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arcsin
PHP: asin
Python: asin

f := numerics.arcsinh( e )

 

trig inverse hyperbolic sine function

Example

f := arcsinh( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the arcsinh value of
f return value universal_numeric required the result

Exceptions

an argument_error if the absolute value of e exceeds 1

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arcsinh
PHP: asinh

f := numerics.arctan( x, y [,cycle] )

 

trig inverse tangent function

Example

f := numerics.arctan( x, y );

Parameters

Param Mode Type Default Description
x,y in universal_numeric required the expression 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

Exceptions

an argument_error when x and y are both zero

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arctan (In Ada, the y parameter is optional.)
PHP: atan
Python: atan

f := numerics.arctanh( e )

 

trig inverse hyperbolic tangent function

Example

f := arctanh( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the arctanh of
f return value universal_numeric required the result

Exceptions

an argument_error if the absolute value of e exceeds 1
a constraint_error when the absolute value of e is 1

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arctanh
PHP: atanh

f := numerics.ceiling( e )

 

Convert a float value to an integer by truncating the decimal part and adding one. This is the smallest integer value that is greater than or equal to Y.

Example

f1 := numerics.ceiling( 5.5 ); -- returns 6
f2 := numerics.ceiling( -5.5 ); -- returns -5

Parameters

Param Mode Type Default Description
e in universal_numeric required the numeric value to take the ceiling of
f return value universal_numeric required the ceiling result

Exceptions

-

See Also

numerics.floor
numerics.rounding
numerics.truncation
numerics.unbiased_rounding

Compare With

Ada: 'ceiling attribute
PHP: ceil
Python: ceil
Java: java.lang.Math.ceil

f := numerics.copy_sign( x, y )

 

return float x with sign of float y

Example

f := numerics.copy_sign( 5.5, -1.0 ); -- returns -5.5

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

-

Compare With

Ada: 'copy_sign attribute

f := numerics.cos( e [,cycle] )

 

trig cosine function

Example

f := numerics.cos( numerics.pi );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression 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

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.cos
PHP: cos
Python: cos

f :=numerics.cosh( e )

 

trig hyperbolic cosine function

Example

f := cosh( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the cosh of
f return value universal_numeric required the result

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.cosh
PHP: cosh

f := numerics.cot( e [,cycle] )

 

trig cotangent function

Example

f := numerics.cot( numerics.pi );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression 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

Exceptions

a constraint_error when e is zero

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.cot

f := numerics.coth( e )

 

trig hyperbolic cotangent function

Example

f := coth( numerics.pi );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the coth of
f return value universal_numeric required the result

Exceptions

a constraint_error when e is zero
a constraint_error when e is zero or a multiple of the half cycle

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.coth

f := numerics.even( i )

 

true if integer i is an even number

Example

f := numerics.even( 2 ); -- true

Parameters

Param Mode Type Default Description
i in integer required the value to test
f return value boolean required true if integer is even

Exceptions

-

See Also

numerics.odd

Compare With

Ada: x mod 2 = 0

f := numerics.exp( e )

 

returns e raised to the power of x where e is epsilon, the base of the natural system of logarithms

Example

f := exp( 1.0 );

Parameters

Param Mode Type Default Description
e in universal_numeric required the power to raise epsilon to
f return value universal_numeric required the result

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.exp
Python: exp

f := numerics.exponent( e )

 

Ada's normalized exponent attribute. It is used to break up a floating point number into its exponent and fraction parts by giving the gross magnitude of e.

Example

f := numerics.exponent( 10.0 ); -- returns 4

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression
f return value universal_numeric required the result

Exceptions

-

See Also

numerics.fraction

Compare With

Ada: 'exponent attribute

f := numerics.floor( e )

 

Convert a float value to an integer by truncating the decimal part. This is different from truncation. The function yields the largest (most positive) integral value less than or equal to X. When X is zero, the result has the sign of X; a zero result otherwise has a positive sign

Example

f1 := numerics.floor( 5.5 ); -- returns 5
f2 := numerics.floor( -5.5 ); -- returns -6

Parameters

Param Mode Type Default Description
e in universal_numeric required the numeric value to truncate
f return value universal_numeric required the truncated result

Exceptions

-

See Also

numerics.ceiling
numerics.rounding
numerics.truncation
numerics.unbiased_rounding

Compare With

Ada: 'floor attribute
PHP: floor
Python: floor
Java: java.lang.Math.floor

f := numerics.fnv_hash_of( s, l )

 

Calculate a 32-bit number from string s that can be used with hash tables using a Fowler-Null-Vo / FNV-1a hash (used by DNS's). The return value is will be between 1 and the limit l.

Example

f := numerics.fnv_hash_of( "apple", 10 ); -- returns 1 to 10

Parameters

Param Mode Type Default Description
s in universal_string required the string expression
l in natural required the maximum value to return
f return value natural required the hash value

Exceptions

-

See Also

numerics.hash_of
numerics.murmur_hash_of
numerics.sdbm_hash_of

Compare With

-

f := numerics.fraction( e )

 

Ada's fraction attribute. The function yields the value X*T'Machine_Radix**(-k), where k is the normalized exponent of X. It is used to break up a floating point number into its exponent and fraction parts.

Example

f := numerics.fraction( 10.0 ); -- returns 0.625

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression
f return value universal_numeric required the result

Exceptions

-

See Also

numerics.exponent

Compare With

Ada: 'fraction attribute
Python: modf

f := numerics.hash_of( s, l )

 

Calculate a 32-bit number from string s that can be used with hash tables using a common standard Bernstein / Knuth / djb2 hash. The return value is will be between 1 and the limit l.

Example

f := numerics.hash_of( "apple", 10 ); -- returns 1 to 10

Parameters

Param Mode Type Default Description
s in universal_string required the string expression
l in natural required the maximum value to return
f return value natural required the hash value

Exceptions

-

See Also

numerics.fnv_hash_of
numerics.murmur_hash_of
numerics.sdbm_hash_of

Compare With

-

f := numerics.leading_part( x, y )

 

Ada's leading part attribute. Let v be the value T'Machine_Radix**(k-Radix_Digits), where k is the normalized exponent of X. The function yields the value Floor(X/v)*v, when X is nonnegative and Radix_Digits is positive; Ceiling(X/v)*v, when X is negative and Radix_Digits is positive. Constraint_Error is raised when Radix_Digits is zero or negative. A zero result, which can only occur when X is zero, has the sign of X. This is used for high precision mathematics.

Example

f := numerics.leading_part( x, y );

Parameters

Param Mode Type Default Description
x,y in universal_numeric required the expressions
f return value universal_numeric required the result

Exceptions

-

See Also

-

Compare With

Ada: 'leading_part attribute

f := numerics.log( e [,b] )

 

logarithm, return a number is the exponent e by which another fixed value, the base b, has to be raised to produce that number. Without base b, the natural logarithm is returned.

Example

f := numerics.log( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expressions to take the log of
b in universal_numeric epsilon (I think) the base of the log
f return value universal_numeric required the result

Exceptions

an argument_error is raised if the base is negative, 0, 1 or if e is negative
a constraint_error is raised if e is zero

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.log
PHP: log
Python: log/log10

f := numerics.machine( e )

 

Ada's machine attribute. If e is a machine number of the type T, the function yields e; otherwise, it yields the value obtained by rounding or truncating e to either one of the adjacent machine numbers of the type T. A zero result has the sign of e when a machine has signed zeros.

Example

f := numerics.machine( 10.0 ); -- returns 10.0

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression
f return value universal_numeric required the result

Exceptions

Constraint_Error is raised if rounding or truncating e to the precision of the machine numbers results in a value outside the base range of S.

See Also

-

Compare With

Ada: 'machine attribute

f := numerics.max( x, y )

 

return the larger of x and y

Example

f := numerics.max( 1.0, 2.0 );

Parameters

Param Mode Type Default Description
x,y in universal_numeric required the expressions to be compared
f return value universal_numeric required the result

Exceptions

-

See Also

numerics.min

Compare With

Ada: 'max attribute
PHP: max
Python: max

r := numerics.md5( s )

 

return the message digest 5 fingerprint of string s

Example

sig := numerics.md5( "Checksum for this message" );

Parameters

Param Mode Type Default Description
s in string required the string to generate an MD5 checksum for
r return value string required the MD5 checksum

Exceptions

-

See Also

-

Compare With

PHP: md5

Implementation Notes

Uses MD5 package from www.AdaPower.com

f := numerics.min( x, y )

 

return the smaller of x and y

Example

f := numerics.max( 1.0, 2.0 );

Parameters

Param Mode Type Default Description
x,y in universal_numeric required the expressions to be compared
f return value universal_numeric required the result

Exceptions

-

See Also

numerics.max

Compare With

Ada: 'min attribute
PHP: min
Python: min

f := numerics.modulus( e [,cycle] )

 

trig inverse consine function

Example

f := numerics.arccos( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expressions 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

Exceptions

an argument_error if the absolute value of e exceeds 1

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.arccos
PHP: acos

f := numerics.murmur_hash_of( s, l )

 

Calculate a 32-bit number from string s that can be used with hash tables using a Murmur hash (used by memcached). The return value is will be between 1 and the limit l.

Example

f := numerics.murmur_hash_of( "apple", 10 ); -- returns 1 to 10

Parameters

Param Mode Type Default Description
s in universal_string required the string expression
l in natural required the maximum value to return
f return value natural required the hash value

Exceptions

-

See Also

numerics.fnv_hash_of
numerics.hash_of
numerics.sdbm_hash_of

Compare With

-

f := numerics.odd( x )

 

odd function

Example

f := numerics.odd( 1 ); -- true

Parameters

Param Mode Type Default Description
x in integer required the value to test
f return value boolean required true if integer is odd

Exceptions

-

See Also

numerics.even

Compare With

Ada: N/A ( x mod 2 = 1 )

p := numerics.pos( c )

 

return the ASCII value (ordinal position) of character c

Example

p := numerics.pos( 'a' ); -- returns 97
p := numerics.pos( ASCII.Quotation ); -- returns 34

Parameters

Param Mode Type Default Description
c in universal_string required the expression to take the position of
p return value positive required the position

Exceptions

an exception is raised if c is a string with a length of 0 or more than 1

See Also

-

Compare With

Ada: 'pos attribute
PHP: ord

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

Parameters

Param Mode Type Default Description
f return value float required the random number

Exceptions

-

See Also

numerics.rnd

Compare With

Ada Equivalent: Ada.Numerics.Float_Random.Random
Python: random

r := numerics.rnd( p )

 

generate a random positive number between 1 and p

Example

r := numerics.rnd( 10 ); -- 1 to 10

Parameters

Param Mode Type Default Description
p in positive required the maximum positive number to return
r return value positive required the random number

Exceptions

-

See Also

numerics.random

Compare With

PHP: rand / mt_rand
Python: uniform

i := numerics.rotate_left( e, b )

 

rotate expression e up to 64 bits left by natural b bits, each step multiplying by two. The highest bits are appended to the bottom.

Example

p := numerics.rotate_left( 16, 2 ); -- returns 64

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

numerics.rotate_right
numerics.shift_left
numerics.shift_right
numerics.shift_right_arithmetic

Compare With

Ada: Interfaces.Rotate_Left

i := numerics.rotate_right( e, b )

 

rotate expression e up to 64 bits right by natural b bits, each step dividing by two. The lowest bits are appended to the top.

Example

f := numerics.rotate_right( 16, 2 ); -- returns 4

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

numerics.rotate_left
numerics.shift_left
numerics.shift_right
numerics.shift_right_arithmetic

Compare With

Ada: Interfaces.Rotate_Right

f := numerics.remainder( x, y )

 

remainder of a floating point divide of x by y. According to the Ada Reference Manual: For nonzero Y, let v be the value X-n*Y, where n is the integer nearest to the exact value of X/Y; if |n-X/Y|=1/2, then n is chosen to be even. If v is a machine number of the type T, the function yields v; otherwise, it yields zero. Constraint_Error is raised if Y is zero. A zero result has the sign of X when a machine has signed zeros.

Example

f := numerics.remainder( 16.5, 2.0 ); -- return 0.5

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

-

Compare With

Ada: 'remainder attribute

f := numerics.rounding( e )

 

Round a float value to an integer. Round to the farthest from zero if exactly between two integers. That is, 5.5 will round up to 6 and 6.5 will round to 7.

Example

f := numerics.rounding( 5.5 ); -- returns 6

Parameters

Param Mode Type Default Description
e in universal_numeric required the numeric value to round
f return value universal_numeric required the rounded result

Exceptions

-

See Also

numerics.ceiling
numerics.floor
numerics.truncation
numerics.unbiased_rounding

Compare With

Ada: 'rounding attribute
PHP: round
Python: round
Java: java.lang.Math.round

f := numerics.scaling( x, y )

 

multiply floating point number by 2 to the power of integer y. Let v be the value X*T'Machine_Radix**Adjustment. If v is a machine number of the type T, or if |v|>=T'Model_Small, The function yields v; otherwise, it yields either one of the machine numbers of the type T adjacent to v. A zero result has the sign of X when a machine has signed zeros. This is used for high precision mathamatics.

Example

f := numerics.scaling( 5.5, 3 ); -- returns 44

Parameters

Param Mode Type Default Description
x in universal_numeric required the expression
y in integer required the power to scale by
f return value universal_numeric required the result

Exceptions

Constraint_Error may be raised

See Also

-

Compare With

Ada: 'scaling attribute

f := numerics.sdbm_hash_of( s, l )

 

Calculate a 32-bit number from string s that can be used with hash tables using a Sleepycat / sdbm hash. The return value is will be between 1 and the limit l.

Example

f := numerics.sdbm_hash_of( "apple", 10 ); -- returns 1 to 10

Parameters

Param Mode Type Default Description
s in universal_string required the string expression
l in natural required the maximum value to return
f return value natural required the hash value

Exceptions

-

See Also

numerics.fnv_hash_of
numerics.hash_of
numerics.murmur_hash_of

Compare With

-

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;

Parameters

Param Mode Type Default Description
f return value natural required the serial number result

Exceptions

-

See Also

-

Compare With

-

i := numerics.shift_left( e, b )

 

shift expression e up to 64 bits left by natural b bits, each step multiplying by two. The highest bits are discarded. The sign bit will be overwritten.

Example

f := numerics.shift_left( 16, 2 ); -- returns 64

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

numerics.rotate_left
numerics.rotate_right
numerics.shift_right
numerics.shift_right_arthmetic

Compare With

Ada: Interfaces.Shift_Left
PHP: <<

i := numerics.shift_right( e, b )

 

shift expression e up to 64 bits right by natural b bits, each step dividing by two. The lowest bits are discarded.

Example

f := numerics.shift_right( 16, 2 ); -- returns 4

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

numerics.rotate_left
numerics.rotate_right
numerics.shift_left
numerics.shift_right_arithmetic

Compare With

Ada: Interfaces.Shift_Right
PHP: >>

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 );

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

numerics.rotate_left
numerics.rotate_right
numerics.shift_left
numerics.shift_right

Compare With

Ada: Interfaces.Shift_Right_Arithmetic

f := numerics.sin( e [,cycle] )

 

trig sine function

Example

f := numerics.sin( numerics.pi );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression 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

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.sin
PHP: sin
Python: sin

f := numerics.sinh( e )

 

trig hyperbolic sine function

Example

f := numerics.sinh( numerics.pi );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the sinh of
f return value floating point required the result

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.sinh
PHP: sinh

f := numerics.sqrt( e )

 

square root of e

Example

f := numerics.sqrt( 9.0 ); -- returns 3.0

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the square root of
f return value floating point required the result

Exceptions

an exception may be thrown if e is negative

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.sqrt
PHP: sqrt
Python: sqrt

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. This is used for setting the scale of graphs.

Example

f := numerics.sturges( 18, 64, 421 );

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

-

Compare With

-

Implementation Note

This should probably be moved to the stats package.

f := numerics.tan( e [,cycle] )

 

trig tangent function

Example

f := numerics.tan( numerics.pi );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression 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

Exceptions

a constraint_error when e is an odd multiple of the quarter cycle

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.tan
PHP: tan
Python: tan

f := numerics.tanh( e )

 

trig hyperbolic tangent function

Example

f := tanh( e );

Parameters

Param Mode Type Default Description
e in universal_numeric required the expression to take the tanh of
f return value universal_numeric required the result

Exceptions

-

See Also

-

Compare With

Ada: Ada.Numerics.Generic_Elementary_Functions.tanh
PHP: tanh

f := numerics.truncation( e )

 

Convert a float value to an integer by truncating the decimal part. This is different from floor. The function yields the value ceiling(e) when e is negative, and floor(e) otherwise. A zero result has the sign of e when a machine has signed zeros.

Example

f1 := numerics.truncation( 5.5 ); -- returns 5
f2 := numerics.truncation( -5.5 ); -- returns -5

Parameters

Param Mode Type Default Description
e in universal_numeric required the numeric value to truncate
f return value universal_numeric required the truncated result

Exceptions

-

See Also

numerics.ceiling
numerics.floor
numerics.rounding
numerics.unbiased_rounding

Compare With

Ada: 'truncation attribute
PHP: N/A
Java: N/A

 

f := numerics.unbiased_rounding( e )

 

Round a float value to an integer. Round to the nearest even integer 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_rouding( 7.5 ); -- returns 8

Parameters

Param Mode Type Default Description
e in universal_numeric required the numeric value to round
f return value universal_numeric required the rounded result

Exceptions

-

See Also

numerics.ceiling
numerics.floor
numerics.rounding
numerics.truncation

Compare With

Ada: 'unbiased_rounding attribute
PHP: round
Java: java.lang.Math.rint

 

f := numerics.value( s )

 

Convert string s to a numeric value (inverse of strings.image). The string is trimmed first. This function only parses numbers.

Example

f := numerics.value( " 32.5" ) * numerics.value( "-1.2" );

Parameters

Param Mode Type Default Description
s in universal_string required the string value to evaluate
f return value universal_numeric required the numeric value

Exceptions

An exception will be raised with any string that cannot be converted.

See Also

strings.image
numerics.pos

Compare With

Ada: 'value attribute
PHP: floatval, etc.
Java: parseFloat, etc.

 
[Right Submenu]

 Summary

 arrays

 btree_io

 calendar

 cgi

 chains

 command_line

 db/ postgresql

 dbm

 directory_operations

 doubly_linked...

 dynamic_hash_...

 enums

 exceptions

 files

 gnat.cgi

 gnat.crc32

 hash_io

 lock_files

 memcache

 memcache.highread

 mysql

 mysqlm

 numerics

 os

 pen

 pen (OpenGL)

 records

 sound

 source_info

 stats

 strings

 System

 teams

 templates

 text_io

 units

[Back to Top] Back To Top [Small Forte Symbol]