axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] Re: i-output and decimal width


From: Stephen Wilson
Subject: [Axiom-developer] Re: i-output and decimal width
Date: 03 Aug 2007 16:39:00 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

address@hidden writes:

> Stephen,
> 
> A couple questions. 
> 
> Where does the problem arise?

On my machine, a call to log10:

  (1) -> )lisp (log10 1000)

  Value = 2.9999998211860652

So the delta 0.0000001 is not enough to push the result so that floor
gives the needed result (hence the version I posted which uses round).

> Can you show before-and-after examples of the change?

On my machine:

   (1) -> )lisp (1+ (floor (+ (log10 100) 0.0000001)))

   Value = 2
   (1) -> )lisp (1+ (round (log10 100)))
 
   Value = 3
   (1) -> )lisp (1+ (floor (+ (log10 1000) 0.0000001)))

   Value = 3
   (1) -> )lisp (1+ (round (log10 1000)))

   Value = 4

I believe this is accurate for integers less than
most-positive-long-float.

> 
> Is computing the log of very large numbers efficient?
> (This isn't an issue if we only cover the first case)

It is not so much efficiency as it is concern for overflow in the
intermediate float calculations.

Ideally, we could just call out to mpz_sizeinbase for very large
numbers, but this is not a portable solution. 


> Since there are only a few cases might it be cheaper
> to compute the length of numbers by range and do
>  u < 10 ==> 1
>  u < 100 ==> 2
>  u < 1000 ==> 3
> rather than compute the log?

If efficiency is not a concern, we could just do repeated divisions
and count the iterations.  I think this would be OK.  We could handle
all cases (small or large integers) this way and we would at least get
exact results (which we need in this situation to guide the output
routines).  If this sounds reasonable I could get a patch together
tonight.


Take care,
Steve








reply via email to

[Prev in Thread] Current Thread [Next in Thread]