Commit ca35b8fc authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

When adding epsilon, make sure that is <0.5. (gnumeric_fake_round,

2005-02-04  Morten Welinder  <terra@gnome.org>

	* src/mathfunc.c (gnumeric_fake_floor, gnumeric_fake_ceil): When
	adding epsilon, make sure that is <0.5.
	(gnumeric_fake_round, gnumeric_fake_trunc): Simplify in terms of
	gnumeric_fake_floor.
parent 1bd8981d
2005-02-04 Morten Welinder <terra@gnome.org>
* src/mathfunc.c (gnumeric_fake_floor, gnumeric_fake_ceil): When
adding epsilon, make sure that is <0.5.
(gnumeric_fake_round, gnumeric_fake_trunc): Simplify in terms of
gnumeric_fake_floor.
2005-02-03 Morten Welinder <terra@gnome.org>
* src/dependent.c: eliminate code predating micro hashes.
......
......@@ -29,6 +29,7 @@ Morten:
* Fix SUBSTITUTE. [#165996]
* Fix general format's use of "e".
* Plug dependency leak. [#159581]
* Fix fake rounding functions for very large numbers. [#166188]
--------------------------------------------------------------------------
Gnumeric 1.4.2
......
2005-02-04 Morten Welinder <terra@gnome.org>
* src/mathfunc.c (gnumeric_fake_floor, gnumeric_fake_ceil): When
adding epsilon, make sure that is <0.5.
(gnumeric_fake_round, gnumeric_fake_trunc): Simplify in terms of
gnumeric_fake_floor.
2005-02-03 Morten Welinder <terra@gnome.org>
* src/dependent.c: eliminate code predating micro hashes.
......
......@@ -175,9 +175,14 @@ gnumeric_sub_epsilon (gnm_float x)
gnm_float
gnumeric_fake_floor (gnm_float x)
{
return (x >= 0)
? floorgnum (gnumeric_add_epsilon (x))
: floorgnum (gnumeric_sub_epsilon (x));
static const gnm_float cutoff = 0.5 / GNUM_EPSILON;
if (gnumabs (x) < cutoff)
x = (x >= 0)
? gnumeric_add_epsilon (x)
: gnumeric_sub_epsilon (x);
return floorgnum (x);
}
/*
......@@ -191,25 +196,28 @@ gnumeric_fake_floor (gnm_float x)
gnm_float
gnumeric_fake_ceil (gnm_float x)
{
return (x >= 0)
? ceilgnum (gnumeric_sub_epsilon (x))
: ceilgnum (gnumeric_add_epsilon (x));
static const gnm_float cutoff = 0.5 / GNUM_EPSILON;
if (gnumabs (x) < cutoff)
x = (x >= 0)
? gnumeric_sub_epsilon (x)
: gnumeric_add_epsilon (x);
return ceilgnum (x);
}
gnm_float
gnumeric_fake_round (gnm_float x)
{
return (x >= 0)
? floorgnum (gnumeric_add_epsilon (x + 0.5))
: -floorgnum (gnumeric_add_epsilon (-x + 0.5));
gnm_float y = gnumeric_fake_floor (gnumabs (x) + 0.5);
return (x < 0) ? -y : y;
}
gnm_float
gnumeric_fake_trunc (gnm_float x)
{
return (x >= 0)
? floorgnum (gnumeric_add_epsilon (x))
: -floorgnum (gnumeric_add_epsilon (-x));
gnm_float y = gnumeric_fake_floor (gnumabs (x));
return (x < 0) ? -y : y;
}
/* ------------------------------------------------------------------------- */
......
Markdown is supported
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