RE: Digest for EUforum at topica.com, issue 5330
- Posted by Cuvier Christian <christian.cuvier at insee.fr> Nov 03, 2005
- 454 views
> Subject: Re: math question > > posted by: Larry Miller <larrymiller at sasktel.net> > > An easy way to extract the low DWORD from an atom is to use the remainder() > > function as in a = remainder(a, #100000000). Bitwise functions such as and_bits() are restricted to numbers #FFFFFFFF or less for both parameters so can not be used for this purpose. A potential problem is that remainder() will return a fractional part if the original number is not an integer. The use of floor() or a rounding function may be necessary if this is a possibility. > > Larry Miller True. The original question, hoxever was about getting the exact value of the low dworsd of the product of two dwords. An atom is not a 64-bit integer, but a float with 53 digit precision. To check that, look for a discussion in this list about the greatest integer arithmetically known by Euphoria - it's power(2,53)-1. This means that, when taking the product, only the 53 most significant bits will be retained - this is fine as long as the product lies below the 2^53 limit -, while exact accuracy aof the 32 less significant bits is desired. The proposed simple solution just can't work as a result, since the 11 LSB can be lost when converting an atom to a 64-bit integer - more precisely max(0,MSB(product)-53). The MSB of the product is the sum of the %MSBs plus perhaps 1. CChris