Re: test whether a double is even?
From: Niki Estner (niki.estner_at_cube.net)
Date: 11/25/03
- Next message: Phlip: "Re: OOB or prosedural"
- Previous message: TLOlczyk: "Re: Versioning CVS or RCS"
- In reply to: John Smith: "Re: test whether a double is even?"
- Next in thread: John Smith: "Re: test whether a double is even?"
- Reply: John Smith: "Re: test whether a double is even?"
- Reply: John Smith: "Re: test whether a double is even?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 25 Nov 2003 22:56:57 +0100
> On my machine an int is 32 bits, so I would lose precision by converting
> a 39 bit number to an int, would I not? (An unsigned long is also 32
bits.)
Err, yes and no: Your original question was about testing a number if it's
even - exactly the last bit will decide whether this is the case or not. Of
course you may loose precision casting a big number to int, short, or char,
but the result will still be even if the original number was (and vice
versa).
Niki
PS: if you need the precision for other purposes, and assuming you're using
in C/C++: there are 'long double' (80 bit double on a PC) and 'long long'
(64 bit integer on a PC) types.
And, if you want an even/odd test on a number you probably shouldn't use
floating point types - as the name says, the least significant bits may
"float" away - making every number big enough even...
"John Smith" <JSmith@mail.com> schrieb im Newsbeitrag
news:3FC3B418.7010703@mail.com...
> Corey Murtagh wrote:
>
> > If the stored value is always an integer, even though the storage type
> > is floating, just convert it to an int and check. Faster that way than
> > using fmod.
> >
>
> The numbers are pretty big. 224401164137 is typical, which is 39 bits.
> On my machine an int is 32 bits, so I would lose precision by converting
> a 39 bit number to an int, would I not? (An unsigned long is also 32
bits.)
>
> Which brings me to another question. Again, on my machine, a double is
> 64 bits. How many of those bits are available to represent a whole number?
>
>
>
- Next message: Phlip: "Re: OOB or prosedural"
- Previous message: TLOlczyk: "Re: Versioning CVS or RCS"
- In reply to: John Smith: "Re: test whether a double is even?"
- Next in thread: John Smith: "Re: test whether a double is even?"
- Reply: John Smith: "Re: test whether a double is even?"
- Reply: John Smith: "Re: test whether a double is even?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|