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



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.

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, ....
.



Relevant Pages

  • Re: Fortran 2008 (was Re: Statement function host association)
    ... optimizing compiler for f77 code for their hardware. ... Other vendors were involved in this process too. ... compilers, but also there are numerous independent commercial ... 15 years or so of the new language features, array syntax still has ...
    (comp.lang.fortran)
  • Re: Learning embedded coding, which uC?
    ... used Forth 10 or more years ago, modern Forth compilers ... terms of target memory usage. ... bottom-up debugging on the target hardware. ... Stephen Pelc, stephenXXX@xxxxxxxxxxxxxxxxxxxxxxxxxx ...
    (comp.arch.embedded)
  • Re: non-specific os C++ building
    ... C++ is a platform-independent language. ... the C runtime libraries. ... you will have to interface with the hardware ... ... There are C++ compilers ...
    (comp.lang.cpp)
  • Re: Another computer algebra system : smib
    ... run very very well on a common configuration of hardware and software strikes me as far more valuable than trying to water it down so it runs on many different hardware and software configurations. ... The failures of code in one or more of the multiple Sage environments merely illustrates how poorly the notion of "machine independence" is supported by the C specification, current C compilers, and whatever else you need. ...
    (sci.math.symbolic)
  • Re: Same code and different result, Why?
    ... No, it is undefined for all other compilers, as well. ... of sequence point is common for all C/C++ compilers. ... for the course for the technology you are using right now, ... sometimes decided by the underlying hardware, ...
    (microsoft.public.vc.language)