[EMAIL PROTECTED] wrote:
> 
> ... First, here's a version of ROUND that can handle values
> where to-integer chokes, fractions less than one, and negative numbers:
> 
> round: func [n [number!] p [integer!] /local factor neg] [
>         if negative? n [n: (- n)  neg: true]
>     factor: 10.0 ** p
>         n: n * factor + 0.5
>         n: n - (n // 1) / factor
>         either neg [- n][n]
> ]
> 

Excellent!  Thanks for replacing that top-of-the-head QAD with some
real code!

> 
> Note that FORMAT has a refinement /full which won't work without the
> function FULL-FORM. I've been working on this with Larry Palmiter and
> Gerald Goertzel. It'll be available on rebol.org in a couple of days.
> FULL-FORM is meant to give the simplest possible string representation
> of a decimal value that will load back to exactly the same value.
> 
> >> form pi
> == "3.14159265358979"
> >> pi - load form pi
> == 3.10862446895044E-15       ; not equal!
> >> full-form pi
> == "3.141592653589793"
> >> pi - load full-form pi
> == 0                          ; equal!
> 

This sounds seriously non-trivial.  I'm looking forward to it.

-jn-

Reply via email to