Re: checking if a floating point number is equal in value to an integer
- From: analyst41@xxxxxxxxxxx
- Date: 31 Jan 2007 03:22:18 -0800
On Jan 29, 10:31 pm, Tim Prince <tpri...@xxxxxxxxxxxxxxxxxx> wrote:
analys...@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.
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).
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, ....
I checked that LF95 always rounds half-integers up. I think the above
solution takes care of what I want to do. Thank you and the other
posters for all the suggestions.
.
- References:
- Prev by Date: Re: Vista and reading/writing files
- Next by Date: Re: F77 -> F95 Intro Presentation Material
- 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):