Re: Representing decimal part as regular integer on low 16 bits?
- From: Coos Haak <chforth@xxxxxxxxx>
- Date: Wed, 13 Sep 2006 01:25:54 +0200
Op Tue, 12 Sep 2006 23:32:15 +0200 schreef Frank Buss:
<snip>
A quick and dirty implementation in Forth:
A little bit too quick and too dirty I might add ;-)
\ reads a number with 3 digitsWith a 16 bit implementation you lose too much precision here!
: n3 ( n n -- n) drop ;
\ multiplies two 3 digit numbers
: *3 ( n n -- n ) * 1000 / ;
Remember the */ operator that every Forth has, much better precision:
: *3 ( n n -- n ) 1000 */ ;
\ divides two 3 digit number
: /3 ( n n -- n ) swap 1000 * swap / ;
Here too:
: /3 ( n n -- n ) 1000 swap */ ;
1.234 n3 42.123 n3 *3 .3 -> 51.979Does not do what you want in a 16 bit Forth.
51.979 n3 42.123 n3 /3 .3 -> 1.233
Is it possible to write a parser for "n3" in Forth, which reads the next
number sequence like "create" reads the next char sequence? I've read
something about >in, source etc., but don't have an idea how to use it.
In short, use doubles for 16 bit implementations: high word the integer
part, the low word as the fraction times 65536. Adding and subtracting with
the normal D+ and D-.
For 32 bit implementations you could use single precision and normal + and
-. Decimal point between bit 15 and 16.
--
Coos
CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html
.
- References:
- Representing decimal part as regular integer on low 16 bits?
- From: Jean-François Michaud
- Re: Representing decimal part as regular integer on low 16 bits?
- From: Frank Buss
- Representing decimal part as regular integer on low 16 bits?
- Prev by Date: Re: Case sensitivity
- Next by Date: Re: Case sensitivity
- Previous by thread: Re: Representing decimal part as regular integer on low 16 bits?
- Next by thread: Re: Representing decimal part as regular integer on low 16 bits?
- Index(es):
Relevant Pages
|