Hi,
I work in a company which processes data from the
local stock exchange. A problem we are running into is that the exchange
places an upper limit on the number of significant figures in prices
disseminated (10), but the decimal point can float.
This, obviously, sounds like the perfect job for
double. However, we can't afford to lose any precision when it comes to
the prices.
Eg. double a = 2.30 will set a = 2.9999...9 not
2.30. That is unacceptable. The problem, of course, is that doubles
are stored with a floating point with respect to base 2, not base
10.
Has anyone else come across this problem? My
solution was to write a base 10 floating point class (essentially coupling some
integral storage variable with an integral variable containing the location of
the decimal point), but it's not an especially attractive solution. Still,
I can't really think of any other way of doing it. I don't really
seeing it as being particularly onerous to extend this class to handle arbitrary
bases.
Has anyone else ever found themselves in this
position? Would this type of code be suitable for boost, or is it too
mission-specific? I guess the line has to be drawn somewhere, and this
ain't exactly building a rocket...on the other hand, it is tedious enough that
no one really wants to do it. So I don't really know.
Damien