approxEqual() has fooled me for a long time...

Fawzi Mohamed fawzi at gmx.ch
Wed Oct 20 05:58:02 PDT 2010


On 20-ott-10, at 13:59, Lars T. Kyllingstad wrote:

> On Wed, 20 Oct 2010 13:33:49 +0200, Fawzi Mohamed wrote:
>
>> On 20-ott-10, at 13:18, Lars T. Kyllingstad wrote:
>>
>>> [...]
>>> However, I, like most people, am a lot more used to thinking in  
>>> terms
>>> of
>>> digits than bits.  If I need my results to be correct to within 10
>>> significant digits, say, how (if possible) would I use feqrel() to
>>> ensure
>>> that?
>> feqrel(a,b)>33 // 10*log(10)/log(2)
>
> ...which would be the solution of
>
>  2^bits = 10^digits,
>
> I guess.  Man, I've got to sit down and learn some more about FP  
> numbers
> one day.

yes floating point use base 2 numbers: matissa + exponent both base 2.
feqrel gives you how many bits (i.e. base 2 digits) are equal in the  
two numbers.
2^33=8589934592 which has 10 digits.
2^34 has already 11 digits, so having more than 33 binary digits in  
common
means having more than 10 base 10 digits in common.

> Thanks!

you are welcome

Fawzi
>
> -Lars



More information about the Digitalmars-d mailing list