On Jan 15, 2008 12:58 PM, van Nek <van.nek at arcor.de> wrote:
> The workaround I found for defining a function with different local
> fpprec was a three step definition:...
> Is there a more elegant way?
Changing the calculational precision locally is very straightforward:
block([fpprec:100], bfloat(%pi) )
Changing the precision of *reading literal constants* is a little
harder. There are three approaches:
1) use ''(fpprec:...) to change the precision before parsing the rest
of the expression. I find this very ugly and dangerous (like many
uses of ''). And though you can do this "locally" in the sense of
limiting it to one high-level input, you have no more control than
that.
2) use exact notation instead of floating notation for your numbers, e.g.
block([fpprec:100],
bfloat( sqrt(1000000000000000000001*10^-21) ) );
3) use eval_string or parse_string:
I find (2) the most elegant, but perhaps a little clumsy notationally.
I wonder if it might be useful to define (e.g.) 1.234x23 ('x' for
exact) to mean precisely the rational number 1234*10^(23-3).
-s