Maxima gives incorrect results with ceiling



On Fri, Dec 07, 2007 at 10:46:12AM -0600, Barton Willis wrote:
> As Andreas showed, the ceiling (and floor functions) do big float
> evaluation using the current value of fpprec. This isn't ideal--it
> would be better if the function pretty-good-floor-or-ceiling (defined
> in src/nummod) had some logic in it that made a better choice for
> fpprec. Even better would be big float interval evaluation (or my
> favorite evaluation with a running error). This could be made nearly
> foolproof, I think.  Other Maxima functions (sign, for example) would
> also benefit. Such things aren't all that difficult, but they take
> time. Volunteers are welcomed!


A proposal for the method of doing ceiling and floor with exact
results:

in pretty-good-floor-or-ceiling, rather than starting with digits = 25
or whatever the current value is and then incrementing digits by 20,
first bfloat the input to whatever the current precision is. Then
extract the base 2 exponent of the bfloat, and if the exponent is
larger than the current precision, set the current digits to the
appropriate precision necessary to ensure exact integer
representation. The sticky bits are going to be denormalized mantissas
and how many guard digits to use... I think something like this plus
some error checking would work though (handle's the floor case)

(setq f1 ($bfloat x))
(setq f2 (bind-fpprec (+ (caddr f1) 10) ($bfloat x)))
(destructuring-bind ((bfloat &optional 'simp p) m e) f2
	(list (list 'bfloat (+ (caddr f1) 10))   (- m (mod m (^ 2 (- e p)))) e))

;; the mod stuff basically subtracts off the fractional part, which
;; means we're doing a floor operation. The + 10 in the bind-fpprec
;; ensures we have at least 3 decimal digits of guard precision beyond
;; the 1's place. 

This only works when the input is an exact representation though, if
you've already got bfloats on the input, you're not getting any better
precision than the least precise bfloat

-- 
Daniel Lakeland
dlakelan at street-artists.org
http://www.street-artists.org/~dlakelan