delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/12/10:30:48

Message-ID: <3530CED8.1173@pobox.oleane.com>
Date: Sun, 12 Apr 1998 16:25:28 +0200
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
CC: djgpp AT delorie DOT com
Subject: Re: Differences between -lm and not -lm
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980412114735 DOT 3322E-100000 AT is>

Eli Zaretskii wrote:
> 
> On Thu, 9 Apr 1998, Michael Phelps wrote:
> 
> >       number %= (int)pow(10, digit_to_start_with);
> >       number /= (int)pow(10, (digit_to_start_with - length));
> 
> Don't forget that 10 doesn't have an exact representation as a
> floating-point number.  So it is subject to round-off errors.

Not quite. 10, as all integers, *has* an exact floating 
point representation (and all basic, +,-,*,/, integer calculations are 
correctly done in floats). However, pow() (or at least libc pow()) uses 
log2(10) to make its calculations, and log2(10) has no exact 
representation as a floating point number...

Regards,
Francois

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019