Re: checking if a floating point number is equal in value to an integer
- From: ejko123@xxxxxxxxx
- Date: 29 Jan 2007 19:05:49 -0800
On Jan 29, 7:50 pm, ejko...@xxxxxxxxx wrote:
On Jan 29, 6:56 pm, analys...@xxxxxxxxxxx wrote:
I am using float(nint(a)) == a as the test. I'd appreciate any
comments and/or better suggestions.
Apologies for following up on my own post, but you also need
to be careful to force a store into A before applying either your
test or mine. You can run into difficulty if A is retained in a
register
with greater precision than is ultimately stored; it's possible that
the value in the register is not exactly an integer, but the rounded
value stored in memory is an integer value. (Presumably you
want to know whether the value stored in memory is an integer.)
This issue can arise on x86 and PowerPC architectures
if A is the single-precision result of a sequence of floating-point
operations (and can be an issue on x86 if A is double).
You can declare A to be VOLATILE (if your compiler supports
this F2003-ism) or you can put A in a common block (F77) or
module variable (F90). It may also be necessary to compile
with less or no optimization.
--Eric
.
- References:
- Prev by Date: Re: checking if a floating point number is equal in value to an integer
- Next by Date: Re: checking if a floating point number is equal in value to an 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
|