Re: checking if a floating point number is equal in value to an integer
- From: Tim Prince <tprince@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Jan 2007 03:31:04 GMT
analyst41@xxxxxxxxxxx wrote:
I am using float(nint(a)) == a as the test. I'd appreciate any comments and/or better suggestions.anint(a) == a would be faster and have fewer failure possibilities. This depends on what you mean. If you do want nint(), there is no need to use float() and incur its limitations.
Would you accept IEEE style rounding, as supported by nearly all current hardware, and, on such hardware, by C compilers which implement rint() et al? Back when I worked on an Origin, the compiler had a FAST_NINT option which caused nint() to be interpreted as IEEE round to nearest [even]. This rounds -0.5 and 0.5 to 0, 1.5 and 2.5 to 2, ....
Also - I am interested in a NINT function that will use a random number to decide what to do when the argument is an exact half-integer (my idea is to test if 2.0*argument is an exact integer).
.
- Follow-Ups:
- References:
- Prev by Date: Re: checking if a floating point number is equal in value to an integer
- Next by Date: Re: Declaration to get 8-bit (or 16-bit) integer?
- Previous by thread: Re: checking if a floating point number is equal in value to an integer
- Next by thread: Re: checking if a floating point number is equal in value to an integer
- Index(es):
Relevant Pages
|