[Info-vax] VMS Software Q1 '23 Update

Arne Vajhøj arne at vajhoej.dk
Fri Jan 27 19:45:01 EST 2023


On 1/27/2023 1:44 PM, Simon Clubley wrote:
> On 2023-01-26, Arne Vajhøj <arne at vajhoej.dk> wrote:
>> On 1/26/2023 12:05 PM, Single Stage to Orbit wrote:
>>> On Thu, 2023-01-26 at 11:50 -0500, Dave Froble wrote:
>>>>> I am of the opinion that direct testing for equality of floating
>>>>> point numbers should be disallowed by every language and that
>>>>> people should be forced to use an alternative where _they_ have to
>>>>> specify the delta value that 2 numbers should be within before they
>>>>> are considered to be equal.
>>>>
>>>> Well, "have to" or not, that is the only method that works ...
>>>
>>> Or use rounding: IF Math.Round(x,2) = Math.Round(x,2) THEN ..
> 
> You are still directly comparing two approximations

.NET spec for Round guarantees the best approximation.

>                                                      and as Arne points
> out, it's not the same thing as using a delta value

Yep.

>> VB.NET?
>>
>> IF Math.Round(x,2) = Math.Round(y,2) THEN
>>
>> and:
>>
>> IF Math.Abs(x - y) < 0.01 THEN
>>
>> are not fully equivalent.
> 
> This is the only method that is truly robust when you are comparing
> approximations instead of exact values.

I think the optimal method depends on the context. And even
with the last method there is the big question of what is the right
value for the epsilon - there is no magic right answer.

In some contexts the relative difference may be better than the
absolute difference:

IF Math.Abs(x / y - 1.0) < 0.001 THEN

> (This assumes Abs() in the above example is really a floating point Abs()
> instead of an integer Abs()).

.NET has 8 overloads of Abs:

Abs(double) -> double
Abs(decimal) -> decimal
Abs(double,int) -> double
Abs(decimal,int) -> decimal
Abs(double,roundingmode) -> double
Abs(decimal,roundingmode) -> decimal
Abs(double,int,roundingmode) -> double
Abs(decimal,int,roundingmode) -> decimal

Arne








More information about the Info-vax mailing list