IEEE 754 floating point library for BASIC
Posted: Tue Feb 12, 2013 4:06 am
Good day folks.
I have uploaded a WIP ARMbasic Math Library, test application, and spreadsheet.
The lib, while being somewhat mature, is indeed of some work. I would encourage
those of you with a math aptitude to download and offer feedback, input, and
code.
While some of the functions are working as expected, with accuracies approaching
the limits of IEEE 754, there are some that are plain humble at best.
I am by no means a mathematician. I actually struggle with higher level maths.
So, this is a call for help.
What is needed is for someone with an SME caliber math aptitude to scrub the
functions and offer feedback on what the domains should be for the various
functions. I have done some of it, but am (honestly) getting burned out on it
all. I've come to far to stop, and am hoping that someone in the group can
pitch in and help round the 4th turn and pour the gas in, to get it across the
finish line.
The function listing follows. Thanks, in advance, for the help.
Have a good one!
-t
*** Common Functions:
fact - factorials for integers 0 to 34 (all that is representable with IEEE 754)
fix - truncates a real number to an integral
int - ditto
floor - returns the largest integer equal to or less then the arg
ceil - returns the smallest integer equal to or above the arg
round - rounds to the nearest integer
sign - returns +1,0,-1 for positive, zero, or negative numbers
fmod - returns the remainder of the division of the denominator into the
numerator
log10i - returns the integer log10 of a number (basically the power of 10)
powi - returns a number raised to an integer power
sci - returns scientific notation of the passed argument. The mantissa is
returned as a real number in the range of 0 to 9.999999 and a byref'd var is set
with the power of 10 of the argument
*** Power/Exp/Log/Sqrt Series:
sqrt - returns the square-root of a number
exp - returns the value of e raised to the power x
logn - returns the exponent to which the base e must be raised to obtain x
pow - raises x to some power p, and returns x^p as output
log - returns the exponent to which the base 10 must be raised to obtain x
log10 - returns the base-10 logarithm of a number
*** Trigonometric Series:
Note all of these are in radians. To use with proper degrees, multiply the
degree argument with either the constants _deg2rad or _rad2deg to convert
to/from radians. degrees = radians*180/_pi radians = degrees*_pi/180.
reducerange is a helper function to bring numbers into a range while retaining
the phase angles - see the function's comments. Also, a byref'd var is set with
the multiplier representing the number of reductions required and the the
direction of the reduction.
sin - return the Sine
cos - return the Cosine
tan - return the Tangent
atan - return the arc-tangent
asin - return the arc-sine
acos - return the arc-cosine
atan2 - return the magnitude and angle of a point, with respect to origin.
sec - returns the inverse cosine
csc - returns the inverse sine
ctan - returns the inverse tangent
asec - returns the arc-secant
acsc - return the arc co-secant
acot - returns the arc co-tangent
*** Hyperbolic Functions:
sinh - returns the hyperbolic sine
cosh - returns the hyperbolic cosine
tanh - returns the hyperbolic tangent
sech - returns the hyperbolic secant
csch - returns the hyperbolic cosecant
coth - returns the hyperbolic cotangent
asinh - returns the inverse hyperbolic sine
acosh - returns the inverse hyperbolic cosine
atanh - returns the inverse hyperbolic tangent
asech - returns the inverse hyperbolic secant
ascsh - returns the inverse hyperbolic cosecant
acoth - returns the inverse hyperbolic cotangent
*** Random Functions:
init_globals - this must be done in order for the random function to work
znew, wnew, mwc - these are internal helper functions
rand - returns a random between 0 and 1, not inclusive.
randb - returns a random between the two arguments passed.
*** Miscellaneous Functions:
fabs - returns the absolute of the floating point argument
I have uploaded a WIP ARMbasic Math Library, test application, and spreadsheet.
The lib, while being somewhat mature, is indeed of some work. I would encourage
those of you with a math aptitude to download and offer feedback, input, and
code.
While some of the functions are working as expected, with accuracies approaching
the limits of IEEE 754, there are some that are plain humble at best.
I am by no means a mathematician. I actually struggle with higher level maths.
So, this is a call for help.
What is needed is for someone with an SME caliber math aptitude to scrub the
functions and offer feedback on what the domains should be for the various
functions. I have done some of it, but am (honestly) getting burned out on it
all. I've come to far to stop, and am hoping that someone in the group can
pitch in and help round the 4th turn and pour the gas in, to get it across the
finish line.
The function listing follows. Thanks, in advance, for the help.
Have a good one!
-t
*** Common Functions:
fact - factorials for integers 0 to 34 (all that is representable with IEEE 754)
fix - truncates a real number to an integral
int - ditto
floor - returns the largest integer equal to or less then the arg
ceil - returns the smallest integer equal to or above the arg
round - rounds to the nearest integer
sign - returns +1,0,-1 for positive, zero, or negative numbers
fmod - returns the remainder of the division of the denominator into the
numerator
log10i - returns the integer log10 of a number (basically the power of 10)
powi - returns a number raised to an integer power
sci - returns scientific notation of the passed argument. The mantissa is
returned as a real number in the range of 0 to 9.999999 and a byref'd var is set
with the power of 10 of the argument
*** Power/Exp/Log/Sqrt Series:
sqrt - returns the square-root of a number
exp - returns the value of e raised to the power x
logn - returns the exponent to which the base e must be raised to obtain x
pow - raises x to some power p, and returns x^p as output
log - returns the exponent to which the base 10 must be raised to obtain x
log10 - returns the base-10 logarithm of a number
*** Trigonometric Series:
Note all of these are in radians. To use with proper degrees, multiply the
degree argument with either the constants _deg2rad or _rad2deg to convert
to/from radians. degrees = radians*180/_pi radians = degrees*_pi/180.
reducerange is a helper function to bring numbers into a range while retaining
the phase angles - see the function's comments. Also, a byref'd var is set with
the multiplier representing the number of reductions required and the the
direction of the reduction.
sin - return the Sine
cos - return the Cosine
tan - return the Tangent
atan - return the arc-tangent
asin - return the arc-sine
acos - return the arc-cosine
atan2 - return the magnitude and angle of a point, with respect to origin.
sec - returns the inverse cosine
csc - returns the inverse sine
ctan - returns the inverse tangent
asec - returns the arc-secant
acsc - return the arc co-secant
acot - returns the arc co-tangent
*** Hyperbolic Functions:
sinh - returns the hyperbolic sine
cosh - returns the hyperbolic cosine
tanh - returns the hyperbolic tangent
sech - returns the hyperbolic secant
csch - returns the hyperbolic cosecant
coth - returns the hyperbolic cotangent
asinh - returns the inverse hyperbolic sine
acosh - returns the inverse hyperbolic cosine
atanh - returns the inverse hyperbolic tangent
asech - returns the inverse hyperbolic secant
ascsh - returns the inverse hyperbolic cosecant
acoth - returns the inverse hyperbolic cotangent
*** Random Functions:
init_globals - this must be done in order for the random function to work
znew, wnew, mwc - these are internal helper functions
rand - returns a random between 0 and 1, not inclusive.
randb - returns a random between the two arguments passed.
*** Miscellaneous Functions:
fabs - returns the absolute of the floating point argument