On 11/14/06,
<> wrote:
>
> On Nov 14, 2006, at 11:35 AM, S. Robert James wrote:
>
> > I'd like to be able to do:
> >
> > x = 2.0
> > assert x.integral?
> >
> > the :integer method returns false in this case.
> > What would be a good way to write a different method to check?
>
> Maybe it is just me, I don't have a lot of experience with floating
> point
> issues, but this request has a bad smell to it. Once you've decided to
> model something with floating point values it seems a bit unusual to
> want
> to know if any particular value happens to be the exact floating point
> representation of an integer. Isn't the entire notion of equality
> somewhat
> ambiguous in the floating point world? I thought this is usually
> handled by
> asking if two values are within some delta (also represented as a
> floating
> point value) of each other.
>
> Any numerical computation folks out there who can share their wisdom?
>
> Maybe the value should be modeled as an integer with different units
> instead of floating point? For example using units of pennies instead
> of dollars to model monetary values.
>
IEEE floating point can store an exact representation of any integer
that the fp number is large enough to contain.
I've never used it this way, but supposedly that is used to handle
53-bit ints on platforms that have 64-bit floats and only 32-bit ints.
That may or may not be what the OP is trying to do.