From: Mark A. B. <mbo...@ar...> - 2007-08-20 13:08:47
|
Colin Paul Adams wrote: > It seems that truncated_to_integer_64 is not enough in itself, and (in > ISE 6.0) isn't sufficiently accurate anyway. > > My problem is converting 1e100 to an integer. > > The debugger displays this as something like 1.000000000000000006e100 > (I have not counted the the exact number of zeros). > > Calling truncated_to_integer_64 on this produces -9223372036854775808. > > The alternative (which I have adopted) is to convert to MA_DECIMAL > first, using make_from_string ({DOUBLE}.out), works, but gives an > inaccurate value (because of the 6). I guess this is acceptable, as > doubles are inherently inaccurate. > It isn't a fault with ISE, but with computer arithmetic in general. 64-bit integers cover the range -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807, so 1e100 is not representable as an integer (you would need 512-bit integers to represent 1e100). So your method is probably the best general, unless you wanted to test if your double is smaller than max_int, and treat accordingly if above or below. Mark |