From: Martin Glanvill
Subject: Urgent Assitance Required ...
Date: 
Message-ID: <1994Mar13.180821.26294@waikato.ac.nz>
I require *exact* conversion from a single-float to a double-float ;

 (coerce 0.3 'double-float) -> 0.3000001192092896d0

What I require is 0.3 -> 0.3[00000000000]d0 (precisely).

Is there *any* way to do this in general Common Lisp?

Cheers,
 


		           From Martin Glanvill

--===**| "Arm Powered" Dodo Breeder's Association of New Zealand Inc. |**===--	
e-mail     : ···@hoiho.math.waikato.ac.nz	            
								******** 
snail-mail : c/- Dept Mathematics & Statistics			*****/|*
             University of Waikato				****/#|*
             PO Box 3105					***/__|*
             Hamilton 2020					**/~~~|*
             New Zealand					********

When you don't know what to do, walk fast and look worried.
From: David Gadbois
Subject: Re: Urgent Assitance Required ...
Date: 
Message-ID: <2m00ih$b2h@peaches.cs.utexas.edu>
In article <······················@waikato.ac.nz>,
Martin Glanvill <···@waikato.ac.nz> wrote:
>I require *exact* conversion from a single-float to a double-float ;
>
> (coerce 0.3 'double-float) -> 0.3000001192092896d0
>
>What I require is 0.3 -> 0.3[00000000000]d0 (precisely).
>
>Is there *any* way to do this in general Common Lisp?

No.  Unless the FLOAT-RADIX is a power of 10, 0.3 is not exactly
representable.  I can't think of any modern machine that uses non-base
2 radixes.  So this is a problem with any language that uses native
floating point formats.

0.3 isn't even exactly representable in IEEE single-float format;
the closest is 0.30000001.

If you need an exact representation, use rational numbers: 3/10.

--David Gadbois