programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Small tidbit

From: Rick VanNorman <rick_at_neverslow.com>
Date: Mon, 21 Apr 2008 20:25:58 -0500

And for those using SwiftForth in CaSeSeNsItIvE mode:

: (I.F) ( n i f -- addr len )
   SWAP NEGATE >R >R DUP ABS 0 ( N |D| )
   <# R> 0 ?DO # LOOP [CHAR] . HOLD
   BEGIN R> 1+ >R # 2DUP OR 0= UNTIL
   ROT 0< IF [CHAR] - ELSE BL THEN HOLD
   R> 1+ BEGIN DUP 0< WHILE 1+ BL HOLD REPEAT DROP #> ;

: I.F ( N I F -- ) (I.F) TYPE SPACE ;

On Mon, Apr 21, 2008 at 8:00 PM, Rick VanNorman <rick_at_neverslow.com> wrote:
> Hi Everybody,
>
> I've been working with scaled integers a bunch lately, and need
> to present tables of data that is human readable. In my case, integers
> are scaled such that 1.0 = 1,000,000 -- which really isn't hard for
> me to read, but I'm not the one who needs the data. So, in the best
> of Forth traditions, I wrote a new numeric output function.
>
> : (i.f) ( n i f -- addr len )
> swap negate >r >r dup abs 0 ( n |d| )
> <# r> 0 ?do # loop [char] . hold
> begin r> 1+ >r # 2dup or 0= until
> rot 0< if [char] - else bl then hold
> r> 1+ begin dup 0< while 1+ bl hold repeat drop #> ;
>
> : i.f ( n i f -- ) (i.f) type space ;
>
> 12345678 4 6 i.f ==> 12.345678
>
>
> Given a scaled integer N, a number of digits I and F, format the
> integer like a real number. Similar to the %f output function in
> C and Perl and such, but in Forth.
>
> I hope it's useful to someone...
>
> --
> rick
>
> "Remember: Silly is a state of Mind, Stupid is a way of Life". -- Dave Butler
>

-- 
rick
"Remember: Silly is a state of Mind, Stupid is a way of Life". -- Dave Butler
----------------------------------------------------------------------
sftalk_at_forth.com      The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users.  For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Apr 21 2008 - 18:26:47 PDT

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:44 PST