![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

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 ---------------------------------------------------------------------- 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:01:16 PDT
This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:44 PST