View Full Version : floating point helper functions
editcore
04-24-2002, 12:14 AM
are the floating point helper functions (FCMP_*, FDIV, FMUL, etc.)
A. fully supported on all the hardware?
B. reasonably fast? (being defined as timed in terms of sub-milliseconds on most hw)
thanks,
mike.
jikesoft
04-28-2002, 12:04 PM
We made a scientific calculator application on BREW.
You can see screen shot on www.jikesoft.com
Anyway, Floating point operation works fine and reasonably fast.
We can even draw some sinusoidal graphs on the phone in a few seconds.
But the problem is coding is too hard and it's difficult to read the
code because every operator is turned into the functions like FCMP_G, ... ( the readibilty of the source code can't be worst. ),
If the calculation becomes complex, you have to check out all the
parenthesis involved in the expression.
To aviod too being struck by complicated parenthesis, I tried to
divide and conquer the expressions.
Just try.. Here is a some sample I have done.
// temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
temp = FADD(FMUL( FADD( FMUL( FADD( FMUL( MAKE_FLOAT(0.421087371217979714e0),zsq), MAKE_FLOAT(-9.63769093368686593)), zsq), MAKE_FLOAT(30.9572928215376501)),zsq), MAKE_FLOAT(-24.0139179559210510));
// temp = temp/(((1.0*zsq + q2)*zsq + q1)*zsq + q0);
temp = FDIV( temp, FADD( FMUL( FADD(FMUL( FADD( FMUL( MAKE_FLOAT(1.0),zsq ), MAKE_FLOAT(-8.91110902798312337)),zsq),MAKE_FLOAT(19.4809660700889731)),zsq),MAKE_FLOAT(-12.0069589779605255)) );
// temp = temp*z + exp*log2;
temp = FADD( FMUL(temp, z), FMUL( exp, MAKE_FLOAT(0.693147180559945309) ) );
Craig Evans
04-29-2002, 06:34 PM
Originally posted by jikesoft
We made a scientific calculator application on BREW.
You can see screen shot on www.jikesoft.com
Anyway, Floating point operation works fine and reasonably fast.
We can even draw some sinusoidal graphs on the phone in a few seconds.
But the problem is coding is too hard and it's difficult to read the
code because every operator is turned into the functions like FCMP_G, ... ( the readibilty of the source code can't be worst. ),
If the calculation becomes complex, you have to check out all the
parenthesis involved in the expression.
To aviod too being struck by complicated parenthesis, I tried to
divide and conquer the expressions.
Just try.. Here is a some sample I have done.
// temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
temp = FADD(FMUL( FADD( FMUL( FADD( FMUL( MAKE_FLOAT(0.421087371217979714e0),zsq), MAKE_FLOAT(-9.63769093368686593)), zsq), MAKE_FLOAT(30.9572928215376501)),zsq), MAKE_FLOAT(-24.0139179559210510));
// temp = temp/(((1.0*zsq + q2)*zsq + q1)*zsq + q0);
temp = FDIV( temp, FADD( FMUL( FADD(FMUL( FADD( FMUL( MAKE_FLOAT(1.0),zsq ), MAKE_FLOAT(-8.91110902798312337)),zsq),MAKE_FLOAT(19.4809660700889731)),zsq),MAKE_FLOAT(-12.0069589779605255)) );
// temp = temp*z + exp*log2;
temp = FADD( FMUL(temp, z), FMUL( exp, MAKE_FLOAT(0.693147180559945309) ) );
If anyone wants to take this idea and run with it, feel free, BUT
many years ago (10? 15??) as an undergrad project in C, we had to write a calculator that would take prefix, postfix, and inline "strings of operators and digits" and calculate their values.
It was basically a simple stack processing exercise.
Wouldn't it be good to perform something like :
char* floatIn ;
sprintf("((%f*%f + %f)*%f + %f)*%f + %f", p3, zsq, p2, zsq, p1);
float floatOut = calcFloat(&floatIn);
Then have calcFloat parse the string, pushing and popping on the stack recursively, then returning a result.
Each operator corresponds to an "F command", and operates on the results in the stack. Parens are easy to handle to. Pretty easy to do, and it would simplify the readability of your code.
You might even be able to simplify the call by using variable number of parameters ... ie calcFloat("<insert function to calc here>", var1, var2, var3, ...) ;
Just a thought. With stack calls you would need to be careful with heap space though ... however, it should work reasonably well.
Regards,
CSE
vBulletin v3.0.13, Copyright ©2000-2009, Jelsoft Enterprises Ltd.