Commit 7876a2ce authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Fix invalid minimum value for builtin floating types. (ticket #247)

	* mln/value/builtin/floatings.hh: Here.

	* tests/value/builtin/floatings.cc: write test.
parent 6c73505c
2011-11-28 Guillaume Lazzara <z@lrde.epita.fr>
Fix invalid minimum value for builtin floating types. (ticket #247)
* mln/value/builtin/floatings.hh: Here.
* tests/value/builtin/floatings.cc: write test.
2011-11-24 Guillaume Lazzara <z@lrde.epita.fr>
 
* mln/fun/v2v/rgb_to_hsl.hh: Fix constructor declaration.
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
//
......@@ -75,7 +76,12 @@ namespace mln
static float min()
{
static const float min_ = mln::value::internal::limits<float>::min();
// NOTE: limits<float>::min() returns the minimum positive
// value. However, in Milena, min() means the minimum value of the
// possible range value, i.e., the lowest negative
// value. Since float has a symetric range value, we can
// safely use -MAX.
static const float min_ = - mln::value::internal::limits<float>::max();
return min_;
}
static float max()
......@@ -114,7 +120,12 @@ namespace mln
static double min()
{
static const double min_ = mln::value::internal::limits<double>::min();
// NOTE: limits<double>::min() returns the minimum positive
// value. However, in Milena, min() means the minimum value of
// the possible range value, i.e., the lowest negative
// value. Since double has a symetric range value, we can
// safely use -MAX.
static const double min_ = - mln::value::internal::limits<double>::max();
return min_;
}
static double max()
......@@ -131,7 +142,7 @@ namespace mln
typedef double sum;
static const char* name()
{ return "float"; }
{ return "double"; }
};
......
// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of Olena.
//
......@@ -28,11 +29,28 @@
int main()
{
std::cout << "mln_sum_product_(float, float) is `"
<< mln_trait_value_name(mln_sum_product_(float, float)) << "'"
<< std::endl;
// FIXME: Displays `float': probably not good. :(
std::cout << "mln_sum_product_(double, double)) is `"
<< mln_trait_value_name(mln_sum_product_(double, double)) << "'"
<< std::endl;
// Checking sum value type name.
mln_assertion(mln_trait_value_name(mln_sum_product_(float, float)) == std::string("float"));
mln_assertion(mln_trait_value_name(mln_sum_product_(double, double)) == std::string("double"));
// Make sure we return the minimum negative value but not the
// minimum positive value.
mln_assertion(mln_min(float) < 0.);
mln_assertion(mln_min(double) < 0.);
// Make sure the sum value type does not alter precision.
{
float a = mln_max(float) / 3,
b = mln_max(float) / 3;
volatile float c = a + b;
volatile mln_sum_product_(float, float) d = a + b;
mln_assertion(c == d);
}
{
double a = mln_max(double) / 3,
b = mln_max(double) / 3;
volatile double c = a + b;
volatile mln_sum_product_(double, double) d = a + b;
mln_assertion(c == d);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment