Re:Essential facts about floating point calculations
by stinos on Monday July 06, 2015 @08:05AM
(#9838456)
How should one avoid division by zero then?
Good question and in this case I really can't tell, it depends on the problem domain (i.e. is your normal data set numbers greater than 1 or rather smaller then 1e-100) and I'm not sure if is possible (in a feasible way) to write one generic function which works for all cases.
A very good point which I didn't think of! Obviously the 1e-6 figure is specific to the application.
How should one avoid division by zero then? You can't figure out the relative error without a division, can you? For normal comparisons, using a relative error is the way to go but the zero case is different.
On the other hand, using quantities of magnitudes in 1e-30 is already using half the exponent, a change of units may be due here.