Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #1580 > unrolled thread
| Started by | jsgraham <jsgrahamus@yahoo.com> |
|---|---|
| First post | 2011-04-27 13:09 -0600 |
| Last post | 2011-04-28 21:08 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.forth
Printing a floating point number jsgraham <jsgrahamus@yahoo.com> - 2011-04-27 13:09 -0600
Re: Printing a floating point number mhx@iae.nl (Marcel Hendrix) - 2011-04-27 22:03 +0200
Re: Printing a floating point number stephenXXX@mpeforth.com (Stephen Pelc) - 2011-04-27 20:52 +0000
Re: Printing a floating point number jsgraham <jsgrahamus@yahoo.com> - 2011-04-27 15:47 -0600
Re: Printing a floating point number jsgraham <jsgrahamus@yahoo.com> - 2011-04-28 00:49 -0600
Re: Printing a floating point number stephenXXX@mpeforth.com (Stephen Pelc) - 2011-04-28 09:13 +0000
Re: Printing a floating point number mhx@iae.nl (Marcel Hendrix) - 2011-04-28 21:08 +0200
| From | jsgraham <jsgrahamus@yahoo.com> |
|---|---|
| Date | 2011-04-27 13:09 -0600 |
| Subject | Printing a floating point number |
| Message-ID | <ip9pl6$a93$1@speranza.aioe.org> |
How does one do this in Forth? I have VFX Forth and I pushed 3.14 onto the stack and tried executing F., for which I got an UNDEFINED WORD error. I know I'm missing something simple here. Steve
[toc] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2011-04-27 22:03 +0200 |
| Message-ID | <78001308998436@frunobulax.edu> |
| In reply to | #1580 |
jsgraham <jsgrahamus@yahoo.com> writes Re: Printing a floating point number > How does one do this in Forth? I have VFX Forth and I pushed 3.14 onto > the stack and tried executing F., for which I got an UNDEFINED WORD error. > I know I'm missing something simple here. Interlocking problems are always difficult. The solution for your first problem is: 3.14e0 ( 3.14 is a double number and the '.' does not mean what you think it means, that's why modern Forth advises to always write 314. ) Because of the second problem, you will get an error even if you guessed '3.14e' needs to be written. The solution to the second problem is loading the Floating-point package *before* trying to use any of its words (here F. and FP number evaluation). (VFX is not alone in failing to include FP in the default startup, SwiftForth has the same annoying behavior.) The VFX manual has ample documentation on how to do this -- although I still not succeeded in creating a .ini file to handle it automatically for me. -marcel
[toc] | [prev] | [next] | [standalone]
| From | stephenXXX@mpeforth.com (Stephen Pelc) |
|---|---|
| Date | 2011-04-27 20:52 +0000 |
| Message-ID | <4db88103.104803156@192.168.0.50> |
| In reply to | #1580 |
On Wed, 27 Apr 2011 13:09:24 -0600, jsgraham <jsgrahamus@yahoo.com> wrote: >How does one do this in Forth? I have VFX Forth and I pushed 3.14 onto >the stack and tried executing F., for which I got an UNDEFINED WORD error. > >I know I'm missing something simple here. There are three floating point packs for VFX Forth, so you have to select which one to use. In nearly all cases, Lib\Ndp387.fth is the best choice. Assuming that the LIB macro is set up: include %lib%\Ndp387 3.14e0 f. In order to prevent parsing issues, specifying an exponent is good practice. Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads
[toc] | [prev] | [next] | [standalone]
| From | jsgraham <jsgrahamus@yahoo.com> |
|---|---|
| Date | 2011-04-27 15:47 -0600 |
| Message-ID | <ipa2t6$40u$1@speranza.aioe.org> |
| In reply to | #1590 |
Stephen Pelc wrote: > On Wed, 27 Apr 2011 13:09:24 -0600, jsgraham<jsgrahamus@yahoo.com> > wrote: > >> How does one do this in Forth? I have VFX Forth and I pushed 3.14 onto >> the stack and tried executing F., for which I got an UNDEFINED WORD error. >> >> I know I'm missing something simple here. > > There are three floating point packs for VFX Forth, so you have to > select which one to use. In nearly all cases, Lib\Ndp387.fth is the > best choice. Assuming that the LIB macro is set up: > > include %lib%\Ndp387 > 3.14e0 f. > > In order to prevent parsing issues, specifying an exponent is good > practice. > > Stephen > Thanks, Stephen
[toc] | [prev] | [next] | [standalone]
| From | jsgraham <jsgrahamus@yahoo.com> |
|---|---|
| Date | 2011-04-28 00:49 -0600 |
| Message-ID | <ipb2m8$3em$1@speranza.aioe.org> |
| In reply to | #1590 |
Stephen Pelc wrote: > On Wed, 27 Apr 2011 13:09:24 -0600, jsgraham<jsgrahamus@yahoo.com> > wrote: > >> How does one do this in Forth? I have VFX Forth and I pushed 3.14 onto >> the stack and tried executing F., for which I got an UNDEFINED WORD error. >> >> I know I'm missing something simple here. > > There are three floating point packs for VFX Forth, so you have to > select which one to use. In nearly all cases, Lib\Ndp387.fth is the > best choice. Assuming that the LIB macro is set up: > > include %lib%\Ndp387 > 3.14e0 f. > > In order to prevent parsing issues, specifying an exponent is good > practice. > > Stephen > Is there a way to print a float in a base other 10? Steve
[toc] | [prev] | [next] | [standalone]
| From | stephenXXX@mpeforth.com (Stephen Pelc) |
|---|---|
| Date | 2011-04-28 09:13 +0000 |
| Message-ID | <4db92fad.24509129@192.168.0.50> |
| In reply to | #1610 |
On Thu, 28 Apr 2011 00:49:44 -0600, jsgraham <jsgrahamus@yahoo.com> wrote: >Is there a way to print a float in a base other 10? No. Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2011-04-28 21:08 +0200 |
| Message-ID | <58951407998436@frunobulax.edu> |
| In reply to | #1613 |
stephenXXX@mpeforth.com (Stephen Pelc) writes Re: Printing a floating point number
> On Thu, 28 Apr 2011 00:49:44 -0600, jsgraham <jsgrahamus@yahoo.com> wrote:
>>Is there a way to print a float in a base other 10?
> No.
FORTH> needs hexfloat
Creating --- Hexfloat Version 2.01 ---
Convert among IEEE 754 32-bit, 64-bit or 80-bit float,
C99 mixed hex/decimal string, and raw hex string formats.
User words:
xf>hex$ df>hex$ sf>hex$ -- ( F: r -- ) ( -- c-addr u )
hex$>xf hex$>df hex$>sf -- ( c-addr u -- ) ( F: -- r )
xf>mix$ df>mix$ sf>mix$ -- ( F: r -- ) ( -- c-addr u )
mix$>xf mix$>df mix$>sf -- ( c-addr u -- ) ( F: -- r )
Remark: The number of digit groups for hex$ is fixed -- groups
shall have 4 hex digits. Overflow is possible: more
than 8, 16, or 20 digits for sf, df, xf respectively.
Remark: For mix$, sign and integer bit are optional, but `.'
and `p' are mandatory. Contrary to hex$ the number
of groups is free, but the total number of digits
of the mantissa should fit in the target float.
ok
FORTH> pi xf>hex$ TYPE 4000 C90F DAA2 2168 C235 ok
FORTH> pi xf>mix$ TYPE +1.921F B544 42D1 846A p+1 ok
FORTH> 3.14e0 xf>mix$ TYPE +1.91EB 851E B851 EB84 p+1 ok
FORTH> s" +1.91EB 851E B851 EB84 p+1" mix$>xf f. 3.140000 ok
Nothing is impossible in Forth.
-marcel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web