[PPL-devel] [GIT] ppl/ppl(floating_point): Avoid dangerous casts when computing errors.
Fabio Bossi
bossi at cs.unipr.it
Wed Jul 28 11:52:59 CEST 2010
Module: ppl/ppl
Branch: floating_point
Commit: 5a827fc7a229ed6474101c2d951da3aa14c2d358
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=5a827fc7a229ed6474101c2d951da3aa14c2d358
Author: Fabio Bossi <bossi at cs.unipr.it>
Date: Wed Jul 28 11:51:32 2010 +0200
Avoid dangerous casts when computing errors.
---
src/Float.templates.hh | 12 ++++++------
src/Linear_Form.templates.hh | 8 +++++---
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/Float.templates.hh b/src/Float.templates.hh
index a784723..6b911ac 100644
--- a/src/Float.templates.hh
+++ b/src/Float.templates.hh
@@ -109,12 +109,12 @@ const FP_Interval_Type& compute_absolute_error(
PPL_ASSERT(to_compute != NULL);
- // FIXME: the inner cast may be dangerous.
- analyzer_format omega = std::max(
- static_cast<analyzer_format>(pow(f_base,
- static_cast<analyzer_format>(1) -
- f_exponent_bias - f_mantissa_bits)),
- std::numeric_limits<analyzer_format>::denorm_min());
+ // We assume that f_base is a power of 2.
+ analyzer_format omega;
+ int power = static_cast<int>(log2(f_base)) *
+ (1 - f_exponent_bias - f_mantissa_bits);
+ omega = std::max(static_cast<analyzer_format>(ldexpl(1.0, power)),
+ std::numeric_limits<analyzer_format>::denorm_min());
to_compute->build(i_constraint(GREATER_OR_EQUAL, -omega),
i_constraint(LESS_OR_EQUAL, omega));
diff --git a/src/Linear_Form.templates.hh b/src/Linear_Form.templates.hh
index fcb57c7..5bb64c0 100644
--- a/src/Linear_Form.templates.hh
+++ b/src/Linear_Form.templates.hh
@@ -418,9 +418,11 @@ Linear_Form<C>::relative_error(
}
C error_propagator;
- // FIXME: this cast may be dangerous.
- analyzer_format lb = -pow(f_base,
- -static_cast<analyzer_format>(f_mantissa_bits));
+ // We assume that f_base is a power of 2.
+ int power = static_cast<int>(log2(f_base)) *
+ (-f_mantissa_bits);
+ analyzer_format lb = -static_cast<analyzer_format>(ldexpl(1.0, power));
+
error_propagator.build(i_constraint(GREATER_OR_EQUAL, lb),
i_constraint(LESS_OR_EQUAL, -lb));
More information about the PPL-devel
mailing list