Re: Linux oddity

From: lilburne (lilburne_at_godzilla.net)
Date: 10/18/03


Date: Sat, 18 Oct 2003 18:29:54 +0100

Keith S. wrote:
> Hi Folks,
>
> When converting a double to an int, the result is not as
> I'd expect on Linux:
>
> #include <stdio.h>
> int
> main(int argc, char **argv)
> {
> double val = 0.24;
> int multiplier = 2000;
> int result = static_cast<int> (val * multiplier);
> printf("result = %d (should be 480)\n", result);
> return 0;
> }
>
> The above code prints 480 on SunOS and Windows, but on
> Linux with gcc 3.2 it prints 479. Is there a valid
> explanation for this difference?
>

Check the status of the floating point chip. The calculation
may be being done with 80 bit precision in the first two
cases and 64 bit precision in the later case.



Relevant Pages

  • Re: int Versus decimal
    ... INT only uses 4 bytes because it doesn't have the precision that DECIMAL ... How are you hoping to maintain the same precision when converting back ... > I have to keep time series on large amounts of numeric data (millions ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: test whether a double is even?
    ... > On my machine an int is 32 bits, so I would lose precision by converting ... Your original question was about testing a number if it's ... course you may loose precision casting a big number to int, short, or char, ...
    (comp.programming)
  • Re: Linux oddity
    ... > When converting a double to an int, ... The comilers are using diferent rounding rules, ... linux box is rounding down. ...
    (comp.lang.cpp)
  • Re: [Full-disclosure] Linux kernel exploit
    ... Subject: Linux kernel exploit ... This is a NULL pointer dereference in the Econet protocol. ... int rep = 0; ...
    (Full-Disclosure)
  • [Full-disclosure] Dropbear SSH server Denial of Service
    ... Dropbear SSH server Denial of Service ... Dropbear is a relatively small SSH 2 server and client. ... LEAF Bering uClibc - a small Linux firewall/network applicance ... int max_unauth_clients; ...
    (Full-Disclosure)