Boost logo

Boost Users :

Subject: [Boost-users] [math] round to fraction
From: gast128 (gast128_at_[hidden])
Date: 2010-10-26 12:06:18


Hello all,

I couldn't find a functionality like 'round to fraction', which would try
round a floating point value to its nearby fraction portion:

round2fraction(1.4, 0.5); -> 1.5
round2fraction(1.8, 0.5); -> 2.0
round2fraction(1.0, 0.5); -> 1.0
round2fraction(1.25, 0.5); -> 1.5
round2fraction(-1.6, 0.5); -> -1.5

We have here a private implementation, but this is probably not as optimised
as those numerical guru's can come up with. Is this a good suggestion to add
to Boost.Math or overkill?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net