IEEE 754 floating point library for BASIC

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
IEEE 754 floating point library for BASIC
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 squareroot 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 base10 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 arctangent
asin  return the arcsine
acos  return the arccosine
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 arcsecant
acsc  return the arc cosecant
acot  returns the arc cotangent
*** 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 squareroot 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 base10 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 arctangent
asin  return the arcsine
acos  return the arccosine
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 arcsecant
acsc  return the arc cosecant
acot  returns the arc cotangent
*** 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
 Attachments

 AB_Math.lib
 (30.38 KiB) Downloaded 300 times

 test_AB_Math_Lib1.bas
 (24.6 KiB) Downloaded 245 times

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Also, it would be wise, for those folks that may be interested in eventually
getting floats, that they do so sooner vs. later
I overheard a little birdie whispering that the free beta will go away at some
point in the future and that there will be an upgrade fee of $10 for those who
were not early adopters and didn't help out with the beta.
t
getting floats, that they do so sooner vs. later
I overheard a little birdie whispering that the free beta will go away at some
point in the future and that there will be an upgrade fee of $10 for those who
were not early adopters and didn't help out with the beta.
t

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Immediately, I noticed a problem with the defininitions.
integral = integer
int() should be the Greatest integer in X function. Int(9.5) = 10, int(9.5)
=9 See: http://www.mathnstuff.com/math/spoken/h ... s/g/g6.htm
fix() truncates a number; e.g. fix(9.5) = 9; fix(+9.5) = 9
They should be different functions. Not ditto.
> fix  truncates a real number to an integral
>
> int  ditto
>
integral = integer
int() should be the Greatest integer in X function. Int(9.5) = 10, int(9.5)
=9 See: http://www.mathnstuff.com/math/spoken/h ... s/g/g6.htm
fix() truncates a number; e.g. fix(9.5) = 9; fix(+9.5) = 9
They should be different functions. Not ditto.
> fix  truncates a real number to an integral
>
> int  ditto
>

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Nice. I had made it a synonym of fix when it really is a synonym of floor.
Fixed on my end. I'll update the file in the files section when some more fixes
are identified and incorporated.
Thank you.
t
Fixed on my end. I'll update the file in the files section when some more fixes
are identified and incorporated.
Thank you.
t

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
(bump/nudge,ping/poke) I am looking for feedback and assistance.
Is anyone else planning on using floats on the ARMbasic devices?
t
Is anyone else planning on using floats on the ARMbasic devices?
t

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
I'm most definitely going to use floats! I have a bunch of GPS stuff using
Integer math I will convert.
Haven't got started yet though as I'm still trying to load the new firmware on
my Mites and Pros. Only had a day or to to play before going off on vacation for
3 weeks  bad planning on my part.
But I'm sure with Bruce's help I'll be up and running in a couple of days...
Chris
Integer math I will convert.
Haven't got started yet though as I'm still trying to load the new firmware on
my Mites and Pros. Only had a day or to to play before going off on vacation for
3 weeks  bad planning on my part.
But I'm sure with Bruce's help I'll be up and running in a couple of days...
Chris

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Hi Tod,
I'm now up and running on one of my 'Mites. What can I do to help?
I'm moderately proficient with math stuff.
Chris
I'm now up and running on one of my 'Mites. What can I do to help?
I'm moderately proficient with math stuff.
Chris

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Hey, Chris. Glad to hear you're up and running.
I uploaded a math lib and a test app. It is located here: Files > General
Resources > IEEE 754 Floats
Can you run the code and help to vet the lib's functions?
Please let me know if you have any issues.
Thanks.
t
I uploaded a math lib and a test app. It is located here: Files > General
Resources > IEEE 754 Floats
Can you run the code and help to vet the lib's functions?
Please let me know if you have any issues.
Thanks.
t

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Unfortunately the test program is too big for the 'mite. I'll extract the funcs
I use most frequently  exp, log, log10, sqrt, sin/cos, tan, atan  and give
them a try.
Should be interesting.
cp
I use most frequently  exp, log, log10, sqrt, sin/cos, tan, atan  and give
them a try.
Should be interesting.
cp

 Posts: 1462
 Joined: Fri Oct 19, 2012 5:11 am
Re: IEEE 754 floating point library for BASIC
Interesting. Is it not a 32K device? I developed it on one. The FW was 12K
and the lib/test app was 19.2K I believe.?. I remember that I had to fight to
get it to compile as it was too large with my initial test app approach (hence
my getting creative therein).
Regardless, I am thankful for any help and will support the vetting efforts
however it works out  iteratively or otherwise.
Thank you.
t
and the lib/test app was 19.2K I believe.?. I remember that I had to fight to
get it to compile as it was too large with my initial test app approach (hence
my getting creative therein).
Regardless, I am thankful for any help and will support the vetting efforts
however it works out  iteratively or otherwise.
Thank you.
t