[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFA/PATCH gtest - NSNumber float != double
From: |
Alexander Malmberg |
Subject: |
Re: RFA/PATCH gtest - NSNumber float != double |
Date: |
Tue, 21 Jan 2003 23:43:17 +0100 |
David Ayers wrote:
>
> Hello everyone,
>
> I'm working on a set of GDL2 guile tests and ran into a base issue.
> +numberWithFloat: 25.1 and +numberWithDouble: 25.1 are not equal. I've
> attached an patch for gtest on this issue which also updates some other
> changes in the general configuration.
This is expected. 25.1 can not be represented exactly as a floating
point number. When you create a float 25.1, you get the float-number
closest to 25.1, and when you create a double 25.1, you get the
double-number closest to 25.1. These usually aren't the same, so the
comparison is correct.
(In practice, you usually don't compare floating point numbers for exact
equality; instead you use
(fabs(num1-num2)<SOME_SMALL_VALUE_DEPENDENT_ON_LOTS_OF_THINGS).
- Alexander Malmberg