J
jacob navia
Hi
I am adding an optimization to lcc-win:
sqrt(2.0) will provoke now that the constant 1.4142... etc will be
generated instead of generating an actual call.
Details:
-------
The compiler does all calculation in the highest precision
available (long double), and then transforms the result into
the (maybe) lower precision as required.
For instance:
float f = sqrtf(2.0f);
The compiler transforms the input constant in a long double
precision constant, then transforms the result into a float
constant.
This code:
long double ld = sqrt(2.0f);
will provoke a call to sqrt(2.0f) with the 2.0 transformed
into a long double from a float constant, then the
result cast again down into a float from a double, then
cast up again to do the assignment of a float into a long
double. The actual value passed will be
1.414213538169861
and not
1.41421356237309504
as it should be in long double precision.
I hope I did not forget some obscure rule in this. Please
if you think about some problems with this optimization
just answer.
The functions supported are most of the functions in math.h
(sqrt acos sin/cos) etc.
Later I will add strlen of constant strings. (strlen("hello"))
What other functions would you add?
Thanks in advance for your attention.
I am adding an optimization to lcc-win:
sqrt(2.0) will provoke now that the constant 1.4142... etc will be
generated instead of generating an actual call.
Details:
-------
The compiler does all calculation in the highest precision
available (long double), and then transforms the result into
the (maybe) lower precision as required.
For instance:
float f = sqrtf(2.0f);
The compiler transforms the input constant in a long double
precision constant, then transforms the result into a float
constant.
This code:
long double ld = sqrt(2.0f);
will provoke a call to sqrt(2.0f) with the 2.0 transformed
into a long double from a float constant, then the
result cast again down into a float from a double, then
cast up again to do the assignment of a float into a long
double. The actual value passed will be
1.414213538169861
and not
1.41421356237309504
as it should be in long double precision.
I hope I did not forget some obscure rule in this. Please
if you think about some problems with this optimization
just answer.
The functions supported are most of the functions in math.h
(sqrt acos sin/cos) etc.
Later I will add strlen of constant strings. (strlen("hello"))
What other functions would you add?
Thanks in advance for your attention.