[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sqrt C function



* Craig Dickson (crdic@yahoo.com) spake thusly:
> Paul Scott wrote:
> 
> > Well that may date me a little even though I am actively programming at 
> > this moment.  I will research this a little more.  My logic would be it 
> > would break the rules of the language to assume that conversion.
> 
> I don't see how. I see it as a legitimate compiler optimization. If you
> have "double f = 4;", and you compile 4 as a double-precision value
> rather than as an int (which would then require an immediate
> conversion), how could that possibly break a program?

Very simple: double f = 4 may be converted to eg. 4.000000000000000001234,
and any test for (sqrt(f) == 2.0) will fail. Of course if your (generic 
"you", not personal) code is like that, you probably shouldn't be playing 
with floats.

Besides, given the choice between specifying something explicitly and 
trusting a compiler to figure it out for me, guess what I choose?

Dima
-- 
E-mail dmaziuk at bmrb dot wisc dot edu (@work) or at crosswinds dot net (@home)
http://www.bmrb.wisc.edu/descript/gpgkey.dmaziuk.ascii -- GnuPG 1.0.4 public key
One distinguishing characteristic of BOFHen is attention deficit disorder.  
Put me in front of something boring and I can find a near-infinite number 
of really creative ways to bugger off.                  -- Antony De Boer in asr



Reply to: