[gimp] libgimpbase: improve gimp_unit_is_metric()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpbase: improve gimp_unit_is_metric()
- Date: Sun, 17 Nov 2013 20:06:15 +0000 (UTC)
commit 9ffa9ac6e36ee0b3854a0eb2dc895d536e8e16fd
Author: Michael Natterer <mitch gimp org>
Date: Sun Nov 17 21:03:37 2013 +0100
libgimpbase: improve gimp_unit_is_metric()
Don't directly compare doubles, use "ABS (foo - bar) < epsilon".
libgimpbase/gimpunit.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/libgimpbase/gimpunit.c b/libgimpbase/gimpunit.c
index a941c7d..1898fa6 100644
--- a/libgimpbase/gimpunit.c
+++ b/libgimpbase/gimpunit.c
@@ -715,8 +715,8 @@ gimp_unit_is_metric (GimpUnit unit)
if (factor == 0.0)
return FALSE;
- return (factor == 25.4 ||
- factor == 2.54 ||
- factor == 0.254 ||
- factor == 0.0254);
+ return ((ABS (factor - 0.0254) < 1e-7) || /* m */
+ (ABS (factor - 0.254) < 1e-6) || /* dm */
+ (ABS (factor - 2.54) < 1e-5) || /* cm */
+ (ABS (factor - 25.4) < 1e-4)); /* mm */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]