[Openmcl-devel] Floating point precision
Sudhir Shenoy
sshenoy at gol.com
Sat Jan 17 15:37:27 PST 2009
On Jan 18, 2009, at 3:40 AM, R. Matthew Emerson wrote:
>
> On Jan 17, 2009, at 8:18 AM, Sudhir Shenoy wrote:
>
>> Sorry if this is slightly off topic but is there any way (CL standard
>> or CCL specific) to make all floating point computations in double
>> precision? I.e., to ensure that (sqrt 1/3) will return the same value
>> as (sqrt 1/3.0d0) by default (without having to do (sqrt (coerce 1/3
>> 'double-float))?
>>
>> I have tried web searches and can't find an answer to this question
>> so
>> I suspect that there is no standard way but would be grateful if
>> someone can point me to even a CCL-specific method.
>
>
> I don't believe there is any CL-standard way to do that.
>
> The CL spec requires that either an accurate rational result or
> single-float approximation be returned when a SQRT gets a rational
> argument.
>
> http://www.lispworks.com/documentation/HyperSpec/Body/12_acc.htm
>
>
Yes, I see. I had also looked at the code l0-float.lisp and seen that
the coercion is unconditionally done to %short-float.
My question arose from a bug I had in some code for financial
instrument valuation where my results were accurate to about 3
decimals (as compared to a desk calculator) and I thought I was doing
all double-precision arithmetic. I had set *read-default-float-format*
but somewhere in the calculations a rational was being passed to a
math function and was the cause of loss of precision.
Thanks for the help
Sudhir
More information about the Openmcl-devel
mailing list