Re: Identifying an exact binary representation



On Feb 3, 6:28 pm, "Bernhard Enders" <bgen...@xxxxxxxxx> wrote:
Does anybody know of a Fortran (can be Java also) procedure that is
able to identify if a given floating point number has an exact binary
representation? Is there a simple algorithm for this task that I am
missing? Thanks in advance,

Bernhard.

You'd have to start out with the decimal representation, as has been
pointed out, but couldn't youdo something like this:

Suppose the decimal representation is ".1234". Move the decimal point
to right till you have a decimal integer. Integers never get rounded
on conversion to floats. Then just compare 1234. with .1234*10**4. If
they are unequal, then clearly .1234 got rounded. This obviously only
works within a certain range, but depending on your application that
may be ok.

I must say I have an odd feeling about this suggestion - there are a
lot of smart people in this newsgroup and I wonder they are missing
something - or I am!

Daniel Feenberg

.



Relevant Pages

  • Re: question regarding java puzzlers #2
    ... it seems a little wrong-headed to me to use an exact representation ... for something that I think is better thought of as an approximation. ... want to convert doubles to BigDecimals using different rules (which is not in ... reason to assume that the true value has a short decimal representation. ...
    (comp.lang.java.programmer)
  • Re: scwewy answers that dont belong
    ... And while the subject of the thread asks if this is an Excel bug, ... it is simply the nature of binary arithmetic in computers that use a ... depending on the precision of the decimal representation, ... it is interesting that a decimal representation ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Bringing back an old tetration curiosity?
    ... For the exp function ... representation of m/n. ... decimal arguments, there can be problems, because the decimal representation ...
    (sci.math)
  • Re: Concatenating int values
    ... I think you are confusing value with representation. ... describing is an operation on the decimal representation of some integer ... The obvious way in C++ is to create a stringstream, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Micrrowave Numbers (#118)
    ... # 71 seconds is only two keys, but entering 111 is far less movement. ... Unless I'm missing something, ... the microwave interprets the number depends solely on whether the last ... program will never suggest the number of seconds representation, ...
    (comp.lang.ruby)