float to bfloat



>>>>> "Richard" == Richard Fateman <fateman@cs.berkeley.edu> writes:

    Richard> The point of this seems to be that a float can be converted into an
    Richard> exact equivalent rational number, like 0.333333333334  can be converted
    Richard> to 3333333333334/100000000000    or whatever that is reduced to
    Richard> lowest terms and typed with the right number of 3333... .
    Richard> OR one could observe that a very compact rational number, 1/3, is quite
    Richard> close to that float value, and decide to rationalize it to 1/3, even though
    Richard> it isn't the absolute closest.

    Richard> Which would you like?  My recollection is that there is some "epsilon" in
    Richard> the rationalize code in maxima.  If you set it to less than
    Richard> one-unit-in-the-last-place
    Richard> (ULP) of the single or double float representation, then you get the version
    Richard> that Stavros wants.  If you set it to something less, (like 2 ULP)
    Richard> then you would
    Richard> get  1/3 --> floats to  0.33333334  --> bfloats to
    Richard> 0.3333333333333333333333333333
    Richard> instead of                          -->
    Richard> 0.3333333434534534436426908

    Richard> I would prefer having that epsilon around if possible.

Yes there is some maxima rationalize function with an epsilon
somewhere.

I think bfloat(float) should just convert without rationalization.
Then if you really want to rationalize, you can
bfloat(rationalize(float)) if you want.  Current behavior won't really
allow that.

I'm assuming that there is a rationalize function available to the
user.  If not we should add one.

Ray