Re: checking if a floating point number is equal in value to an integer



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

.



Relevant Pages

  • Re: Placement of memory loads
    ... conflicts and high register pressure. ... I may force everything back into memory; ... compiler pretends as if flow proceeds linearly through the function. ...
    (comp.compilers)
  • Re: Two Click disassembly/reassembly
    ... > Map the extra x86 registers to memory. ... > As long as you've got indirection through a register and the ability to ... compiler can't handle here. ... rather than a line by line assembler. ...
    (alt.lang.asm)
  • Re: Layout Hell-o
    ... memory location on a full-word boundary. ... Extra code was generated by the compiler to move the binary-word argument to ... After the binary computation in the register, ... forcing all "01" level data names to full-word boundaries. ...
    (comp.lang.cobol)
  • Re: next mystery: 32 vs 64 bits...
    ... makes a mess out of the x86 32/64 issue... ... we can only get addresses to things in memory. ... 'on stack' typically, is not 'in memory'. ... When i is loaded into a CPU register, ...
    (alt.lang.asm)
  • Re: warning: read-write constraint -- 2.6.15-git8 onwards
    ... whether the compiler used there has an extra, ill patch (after all there's generally nothing wrong for a read-write ... constraint to only allow memory on x86). ... > It seems that the following commit causes a bunch of warnings out of ...
    (Linux-Kernel)