picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

commit cf2c2ef058a188f02aedda1dc90b0e4c1650386e
parent df23b2178c1ab24262ad914b689cbcf6f40b46d6
Author: Commit-Bot <unknown>
Date:   Fri, 18 Jun 2010 10:15:55 +0000

Automatic commit from picoLisp.tgz, From: Fri, 18 Jun 2010 10:15:55 GMT
Diffstat:
Mdoc/ref.html | 3++-
Mdoc/refR.html | 15+++++++++++++++
Mlib/math.l | 7+------
Mlib/misc.l | 7++++++-
Mtest/lib/misc.l | 8+++++++-
5 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/doc/ref.html b/doc/ref.html @@ -1932,11 +1932,12 @@ abbreviations: <a href="refA.html#accu">accu</a> <a href="refF.html#format">format</a> <a href="refP.html#pad">pad</a> + <a href="refM.html#money">money</a> + <a href="refR.html#round">round</a> <a href="refO.html#oct">oct</a> <a href="refH.html#hex">hex</a> <a href="refH.html#hax">hax</a> <a href="refF.html#fmt64">fmt64</a> - <a href="refM.html#money">money</a> </code> <dt>List Processing diff --git a/doc/refR.html b/doc/refR.html @@ -662,6 +662,21 @@ href="refF.html#flip">flip</a></code> . -> (3 1 2 4 5 6) </code></pre> +<dt><a name="round"><code>(round 'num1 'num2) -> sym</code></a> +<dd>Formats a number <code>num1</code> with <code>num2</code> decimal places, +according to the current scale <code><a href="refS.html#*Scl">*Scl</a></code>. +See also <code><a href="refF.html#format">format</a></code> and <code><a +href="ref.html#num-io">Numbers</a></code>. + +<pre><code> +: (scl 4) # Set scale to 4 +-> 4 +: (round 123456 2) # Format with two decimal places +-> "12.35" +: (format 123456 *Scl) # Format with full precision +-> "12.3456" +</code></pre> + <dt><a name="rpc"><code>(rpc 'sym ['any ..]) -> flg</code></a> <dd><i>Rapid</i> (or <i>remote</i>) procedure call: Send an executable list <code>(sym any ..)</code> via standard output in encoded binary format. See also diff --git a/lib/math.l b/lib/math.l @@ -1,4 +1,4 @@ -# 18jun10abu +# 18mar10abu # (c) Software Lab. Alexander Burger (and (=0 *Scl) (scl 6)) # Default scale 6 @@ -8,9 +8,4 @@ (load (if (== 64 64) "@lib/math64.l" "@lib/math32.l")) -(de round (N D) - (if (>= *Scl D) - (format (*/ N (** 10 (- *Scl D))) D) - (format N *Scl) ) ) - # vi:et:ts=3:sw=3 diff --git a/lib/misc.l b/lib/misc.l @@ -1,4 +1,4 @@ -# 14may10abu +# 18jun10abu # (c) Software Lab. Alexander Burger # *Allow *Tmp @@ -121,6 +121,11 @@ (pack (format N 2 *Sep0 *Sep3) " " Cur) (format N 2 *Sep0 *Sep3) ) ) +(de round (N D) + (if (>= *Scl D) + (format (*/ N (** 10 (- *Scl D))) D) + (format N *Scl) ) ) + # Octal notation (de oct (X) (cond diff --git a/test/lib/misc.l b/test/lib/misc.l @@ -1,4 +1,4 @@ -# 04sep08abu +# 18jun10abu # (c) Software Lab. Alexander Burger ### locale ### @@ -69,6 +69,12 @@ (locale) +### round ### +(scl 4) +(test "12.35" (round 123456 2)) +(test "12.3456" (round 123456 6)) + + ### balance ### (test (5 (2 (1) 3 NIL 4) 7 (6) 8 NIL 9) (let I NIL (balance 'I (sort (1 4 2 5 3 6 7 9 8))) I) )