float_to_round function?



On Nov. 3, 2011, Barton Willis wrote:
------------------------------
Maybe something like:

   (%i24) round_some_floats(e) := scanmap(lambda([s], if floatnump(s) and 
                  abs(s-round(s)) * 10^6 < 1 then round(s) else s), e)$

   (%i26) round_some_floats(bessel(1.4,x) * bessel(42.0, 12) + 
               sqrt(33.000001 * x + y) - bessel_j(1/2, 12));

   (%o26) sqrt(y+33*x)+bessel(1.4,x)*bessel(42,12)-bessel_j(1/2,12)
----------------------------------------------------
Yes, that seems to work better than using rat, but not sure which 
        would be better in practice:

 (%i83) round_some_floats(e) := scanmap(lambda([s], if floatnump(s)
        then rat(s) else s), e)$

(%i84) round_some_floats(
         bessel(1.4,x) * bessel(42.0, 12) + 
                sqrt(33.000001 * x + y) - bessel_j(1/2, 12));


(%o84) sqrt(1000000*y+33000001*x)/1000+bessel(7/5,x)*bessel(42,12)
                                      -bessel_j(1/2,12)

----------------------------
Ted