epsilon

Get next smallest Double number

笑着哭i 提交于 2019-11-26 21:59:57
问题 As part of a unit test, I need to test some boundary conditions. One method accepts a System.Double argument. Is there a way to get the next-smallest double value? (i.e. decrement the mantissa by 1 unit-value)? I considered using Double.Epsilon but this is unreliable as it's only the smallest delta from zero, and so doesn't work for larger values (i.e. 9999999999 - Double.Epsilon == 9999999999 ). So what is the algorithm or code needed such that: NextSmallest(Double d) < d ...is always true.

Does “epsilon” really guarantees anything in floating-point computations?

自闭症网瘾萝莉.ら 提交于 2019-11-26 21:12:26
问题 To make the problem short let's say I want to compute the expression a / (b - c) on float s. To make sure the result is meaningful, I can check if b and c are in equal: float EPS = std::numeric_limits<float>::epsilon(); if ((b - c) > EPS || (c - b) > EPS) { return a / (b - c); } but my tests show it is not enough to guarantee either meaningful results nor not failing to provide a result if it is possible. Case 1: a = 1.0f; b = 0.00000003f; c = 0.00000002f; Result: The if condition is NOT met,

python numpy machine epsilon

本秂侑毒 提交于 2019-11-26 10:24:47
问题 I am trying to understand what is machine epsilon. According to the Wikipedia, it can be calculated as follows: def machineEpsilon(func=float): machine_epsilon = func(1) while func(1)+func(machine_epsilon) != func(1): machine_epsilon_last = machine_epsilon machine_epsilon = func(machine_epsilon) / func(2) return machine_epsilon_last However, it is suitable only for double precision numbers. I am interested in modifying it to support also single precision numbers. I read that numpy can be used