Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #53117 > unrolled thread
| Started by | josv@planet.nl |
|---|---|
| First post | 2016-12-06 03:40 -0800 |
| Last post | 2016-12-31 06:42 -0800 |
| Articles | 20 on this page of 149 — 25 participants |
Back to article view | Back to comp.lang.forth
f.) for Gorth josv@planet.nl - 2016-12-06 03:40 -0800
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-06 15:48 +0100
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-06 17:59 +0000
Re: f.) for Gorth josv@planet.nl - 2016-12-06 13:17 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-07 11:11 +0000
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-07 06:11 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-07 17:50 +0000
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-07 15:23 +0100
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-08 16:18 +0000
Re: f.) for Gorth josv@planet.nl - 2016-12-07 06:46 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-07 17:41 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-06 10:34 -0800
Re: f.) for Gorth josv@planet.nl - 2016-12-09 12:11 -0800
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-23 13:23 +1100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-15 15:42 -0800
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-07 13:06 +1100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-06 18:32 -0800
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-07 12:41 +0100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-07 19:49 -0800
Re: f.) for Gorth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-08 08:12 +0000
Re: f.) for Gorth Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-12-08 18:53 -0500
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-09 00:01 +0000
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-09 12:17 +0100
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-09 13:01 +0000
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-09 11:19 +1100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-08 22:23 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-09 07:11 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-20 22:40 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-20 23:59 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-21 21:17 -0800
Re: f.) for Gorth The Beez <the.beez.speaks@gmail.com> - 2016-12-13 08:51 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-09 12:47 +0000
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-10 11:54 +1100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-09 17:28 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-09 18:20 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-10 14:26 +0000
Re: f.) for Gorth The Beez <the.beez.speaks@gmail.com> - 2016-12-13 09:14 -0800
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-13 19:24 +0100
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-14 07:29 -0600
Re: f.) for Gorth Hans Bezemer <the.beez.speaks@gmail.com> - 2016-12-14 18:29 +0100
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-14 10:13 -0800
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-15 03:45 -0600
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-15 10:42 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-15 05:11 -0600
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-15 12:36 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-15 07:33 -0600
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-15 14:31 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-15 14:34 -0600
Re: f.) for Gorth Paul Rubin <no.email@nospam.invalid> - 2016-12-15 16:20 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-15 16:46 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-17 09:23 -0800
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-19 02:56 -0600
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-16 08:10 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-16 10:00 -0600
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-18 10:32 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-19 03:22 -0600
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-16 14:14 +0100
Re: f.) for Gorth Bernd Paysan <bernd@net2o.de> - 2016-12-19 19:41 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-20 03:02 -0600
Re: f.) for Gorth mhx@iae.nl - 2016-12-20 01:27 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-20 12:35 +0000
Re: f.) for Gorth Charles Montgomery <cgm@physics.utoledo.edu> - 2016-12-20 21:23 -0500
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-21 07:29 +0000
Re: f.) for Gorth Charles Montgomery <cgm@physics.utoledo.edu> - 2016-12-21 22:24 -0500
Re: f.) for Gorth "David N. Williams" <williams@umich.edu> - 2016-12-22 08:10 -0500
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-22 17:39 +0000
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-15 12:53 +0100
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-15 05:59 -0600
Re: f.) for Gorth "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-03 16:15 +0000
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-14 17:06 +0000
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-18 10:58 +1100
Re: f.) for Gorth Paul Rubin <no.email@nospam.invalid> - 2016-12-17 17:26 -0800
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-19 13:16 +1100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-18 19:19 -0800
Re: f.) for Gorth john <anon@example.com> - 2016-12-19 11:03 +0000
Re: f.) for Gorth Mark Wills <markwills1970@gmail.com> - 2016-12-20 01:46 -0800
Re: f.) for Gorth john <anon@example.com> - 2016-12-20 12:14 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-20 17:34 -0800
Re: f.) for Gorth Paul Rubin <no.email@nospam.invalid> - 2016-12-18 19:25 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-18 19:45 -0800
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-22 11:32 +1100
Re: f.) for Gorth Bernd Paysan <bernd@net2o.de> - 2017-01-03 19:33 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2017-01-03 22:13 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2017-01-04 23:03 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2017-01-06 22:52 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2017-01-07 22:45 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2017-01-07 17:23 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2017-01-08 09:13 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2017-01-08 17:10 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2017-01-09 10:22 +0000
Re: f.) for Gorth stephen@mpeforth.com - 2017-01-08 07:00 -0800
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-05-20 14:09 +0200
Re: f.) for Gorth Matthias Trute <matthias.trute@gmail.com> - 2017-01-11 01:14 -0800
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-07 12:26 +0100
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-08 10:21 +1100
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-20 15:45 +0100
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-20 15:33 +0000
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-22 11:37 +1100
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-22 14:19 +0100
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-23 12:11 +1100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-22 17:49 -0800
Re: f.) for Gorth "HAA" <someone@microsoft.com> - 2016-12-23 20:41 +1100
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-05-20 14:21 +0200
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-15 22:31 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-16 18:26 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-18 16:41 -0800
Re: f.) for Gorth stephen@mpeforth.com - 2016-12-20 02:20 -0800
Re: f.) for Gorth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-20 13:04 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-20 17:27 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-17 10:36 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-17 11:51 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-18 19:35 -0800
Re: f.) for Gorth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-19 14:17 +0100
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-19 10:10 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-19 20:33 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-19 18:11 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-19 19:03 -0800
Re: f.) for Gorth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-20 08:10 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-20 18:05 -0800
Re: f.) for Gorth - what is a number? Jan Coombs <jenfhaomndgfwutc@murmic.plus.com> - 2016-12-21 09:04 +0000
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-20 15:26 +0000
Re: f.) for Gorth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-20 11:30 -0600
Language stds (was Re: f.) for Gorth) Alex <alex@rivadpm.com> - 2016-12-20 19:49 +0000
Re: Language stds (was Re: f.) for Gorth) john <anon@example.com> - 2016-12-20 20:06 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-20 17:52 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-21 13:47 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-21 20:46 -0800
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-22 14:33 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-22 07:06 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-22 07:21 -0800
Re: f.) for Gorth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-23 07:41 +0000
Re: f.) for Gorth Alex <alex@rivadpm.com> - 2016-12-23 08:33 +0000
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-23 18:22 -0800
Re: f.) for Gorth Julian Fondren <julian.fondren@gmail.com> - 2016-12-23 20:28 -0800
Re: f.) for Gorth hughaguilar96@gmail.com - 2016-12-26 18:30 -0800
Language stds (Re: f.) for Gorth) "HAA" <someone@microsoft.com> - 2016-12-24 12:12 +1100
Re: Language stds (Re: f.) for Gorth) Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-24 03:28 -0600
Re: Language stds (Re: f.) for Gorth) "Elizabeth D. Rather" <erather@forth.com> - 2016-12-24 10:02 -0600
Re: Language stds (Re: f.) for Gorth) hughaguilar96@gmail.com - 2016-12-24 16:13 -0800
Re: Language stds (Re: f.) for Gorth) Alex <alex@rivadpm.com> - 2016-12-24 18:13 +0000
Re: Language stds (Re: f.) for Gorth) "HAA" <someone@microsoft.com> - 2016-12-28 09:24 +1100
Re: Language stds (Re: f.) for Gorth) "Elizabeth D. Rather" <erather@forth.com> - 2016-12-27 17:10 -0600
Re: Language stds (Re: f.) for Gorth) hughaguilar96@gmail.com - 2016-12-27 22:58 -0800
Re: Language stds (Re: f.) for Gorth) "HAA" <someone@microsoft.com> - 2016-12-29 10:12 +1100
Re: Language stds (Re: f.) for Gorth) "Elizabeth D. Rather" <erather@forth.com> - 2016-12-29 17:03 -0800
Re: Language stds (Re: f.) for Gorth) hughaguilar96@gmail.com - 2016-12-29 19:35 -0800
Re: Language stds (Re: f.) for Gorth) Howerd <howerdo@yahoo.co.uk> - 2016-12-30 05:27 -0800
Re: Language stds (Re: f.) for Gorth) hughaguilar96@gmail.com - 2016-12-30 19:11 -0800
Re: Language stds (Re: f.) for Gorth) hughaguilar96@gmail.com - 2016-12-31 06:42 -0800
Page 1 of 8 [1] 2 3 4 5 6 7 8 Next page →
| From | josv@planet.nl |
|---|---|
| Date | 2016-12-06 03:40 -0800 |
| Subject | f.) for Gorth |
| Message-ID | <33ce84eb-b042-440d-8e0c-8134b7db18df@googlegroups.com> |
\ (f.) Makes it very easy to send a floating point number to some target.
\ After looking to f. I now use the following code:
: +pad ( adr cnt -- ) pad +place ;
: f$ ( f -- n )
pad off scratch represent 0=
if 2drop scratch 3 min +pad rdrop exit then
if s" -" +pad then ;
: (f.) ( r -- ) ( -- adr cnt )
\G Writes (the floating-point number) @i{r} without exponent,
\G to a string. Includes last zeros when needed.
f$ dup >r 0<=
if s" 0" +pad
else scratch r@ min +pad r@ precision - zeros
then
s" ." +pad r@ negate zeros
scratch r> 0 max /string 0 max
+pad pad count ;
\ Eg:
: crf. ( f - ) cr (f.) type ;
7 set-precision
-12.3e crf. -1.003e crf.
-1.3e crf. 0e crf.
\\\ Output
-12.30000
-1.003000
-1.300000
0.000000 ok
\ Jos
[toc] | [next] | [standalone]
| From | albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2016-12-06 15:48 +0100 |
| Message-ID | <o26j4f$6u9$1@cherry.spenarnc.xs4all.nl> |
| In reply to | #53117 |
In article <33ce84eb-b042-440d-8e0c-8134b7db18df@googlegroups.com>,
<josv@planet.nl> wrote:
>\ (f.) Makes it very easy to send a floating point number to some target.
>\ After looking to f. I now use the following code:
>
>: +pad ( adr cnt -- ) pad +place ;
>
>: f$ ( f -- n )
> pad off scratch represent 0=
> if 2drop scratch 3 min +pad rdrop exit then
> if s" -" +pad then ;
>
>: (f.) ( r -- ) ( -- adr cnt )
>\G Writes (the floating-point number) @i{r} without exponent,
>\G to a string. Includes last zeros when needed.
> f$ dup >r 0<=
> if s" 0" +pad
> else scratch r@ min +pad r@ precision - zeros
> then
> s" ." +pad r@ negate zeros
> scratch r> 0 max /string 0 max
> +pad pad count ;
>
>\ Eg:
>: crf. ( f - ) cr (f.) type ;
> 7 set-precision
> -12.3e crf. -1.003e crf.
> -1.3e crf. 0e crf.
>
>\\\ Output
>-12.30000
>-1.003000
>-1.300000
>0.000000 ok
>\ Jos
Much preferred:
FINIT
OK
64 BASE !
OK
PI 10 F.R
3.93taY8MZ2D000000000000000000000000000000000000000000000000000000_0 OK
3.93taY8MZ2D000000000000000000000000000000000000000000000000000000_0 PI F=
OK
.
-1 OK
Notes:
- in order to use base 64, the nefarious decision to use
E as an exponent sign must be ignored, which would block bases above 16.
- because 64 is a power of 2, internal representations
can be converted exactly, and by leaving out trailing zeroes,
much space can be gained.
- this doesn't work for "case-insensitive numbers".
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-12-06 17:59 +0000 |
| Message-ID | <2016Dec6.185910@mips.complang.tuwien.ac.at> |
| In reply to | #53117 |
josv@planet.nl writes:
>\ (f.) Makes it very easy to send a floating point number to some target.
>\ After looking to f. I now use the following code:
...
>: (f.) ( r -- ) ( -- adr cnt )
>\G Writes (the floating-point number) @i{r} without exponent,
>\G to a string. Includes last zeros when needed.
Note that Gforth has had F>STR-RDP since 0.6 (2003):
|f>str-rdp rf +nr +nd +np – c-addr nr gforth
|
|Convert rf into a string at c-addr nr. The conversion rules and the
|meanings of nr +nd np are the same as for f.rdp. The result in in the
|pictured numeric output buffer and will be destroyed by anything
|destroying that buffer.
You can find the meaning of the formatting parameters in
<https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Simple-numeric-output.html>
If you just want to use F., but print in a buffer, the current
development version has >STRING-EXECUTE, so you can define
: (f.) ( r -- c-addr u )
['] f. >string-execute ;
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | josv@planet.nl |
|---|---|
| Date | 2016-12-06 13:17 -0800 |
| Message-ID | <a093eec3-ce28-4534-bfd8-abe58dfde6c6@googlegroups.com> |
| In reply to | #53131 |
Hi,
Thank you, that is much better!
>string-execute is indeed very powerful.
When I use it for my needs I get:
: f.73 ( r -- ) 7 3 0 f.rdp ;
: (f.73) ( r -- ) ( -- c-addr u ) ['] f.73 >string-execute ;
\ EG: ok
2e (f.73) type 2.000 ok
-2e (f.73) type -2.000 ok
-20e (f.73) type -20.000 ok
-2.1e (f.73) type -2.100 ok
Saves a lot of coding!
Jos
On 6 december 2016 19:09:50 UTC+1 Anton Ertl wrote:
> jo...nl writes:
> >\ (f.) Makes it very easy to send a floating point number to some target.
> >\ After looking to f. I now use the following code:
> ...
> >: (f.) ( r -- ) ( -- adr cnt )
> >\G Writes (the floating-point number) @i{r} without exponent,
> >\G to a string. Includes last zeros when needed.
>
> Note that Gforth has had F>STR-RDP since 0.6 (2003):
>
> |f>str-rdp rf +nr +nd +np – c-addr nr gforth
> |
> |Convert rf into a string at c-addr nr. The conversion rules and the
> |meanings of nr +nd np are the same as for f.rdp. The result in in the
> |pictured numeric output buffer and will be destroyed by anything
> |destroying that buffer.
>
> You can find the meaning of the formatting parameters in
> <https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Simple-numeric-output.html>
>
> If you just want to use F., but print in a buffer, the current
> development version has >STRING-EXECUTE, so you can define
>
> : (f.) ( r -- c-addr u )
> ['] f. >string-execute ;
>
> - anton
> --
> M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
> comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
> New standard: http://www.forth200x.org/forth200x.html
> EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-12-07 11:11 +0000 |
| Message-ID | <2016Dec7.121119@mips.complang.tuwien.ac.at> |
| In reply to | #53142 |
josv@planet.nl writes:
>Hi,
>Thank you, that is much better!
>>string-execute is indeed very powerful.
>When I use it for my needs I get:
>
>: f.73 ( r -- ) 7 3 0 f.rdp ;
>: (f.73) ( r -- ) ( -- c-addr u ) ['] f.73 >string-execute ;
>STRING-EXECUTE is orginally meant to make printing words like
F. more flexible. In the present case, we have a variant that outputs
to a string, so you could define the above as
: (f.73) ( r -- c-addr u ) 7 3 0 f>str-rdp ;
: f.73 ( r -- ) (f.73) type ;
There is a behavioural difference: F>STR-RDP puts its result in the
pictured numeric output buffer, and it is overwritten by the next use
of that buffer, while >STRING-EXECUTE ALLOCATEs the buffer for the
output string, and you have to FREE it yourself.
From the implementation POV, F.RDP is implemented as
: f.rdp f>str-rdp type ;
so then undoing the TYPE by using >STRING-EXECUTE is not the most
efficient way.
While we are at the topic of >STRING-EXECUTE: Another thing it is good
for is for constructing strings programmatically. E.g., do something
like (untested)
: call-emacs ( c-addr u line column -- )
[: ." emacs +" swap 0 .r ." :" 0 .r space type ;] >string-execute
2dup system free throw ;
Try to write that without >STRING-EXECUTE, and see how much code would
be needed.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2016-12-07 06:11 -0800 |
| Message-ID | <23ba8f31-3755-4c67-8cae-0903d10370e7@googlegroups.com> |
| In reply to | #53152 |
On Wednesday, December 7, 2016 at 6:51:46 AM UTC-6, Anton Ertl wrote:
> While we are at the topic of >STRING-EXECUTE: Another thing it is good
> for is for constructing strings programmatically. E.g., do something
> like (untested)
>
> : call-emacs ( c-addr u line column -- )
> [: ." emacs +" swap 0 .r ." :" 0 .r space type ;] >string-execute
> 2dup system free throw ;
>
> Try to write that without >STRING-EXECUTE, and see how much code would
> be needed.
Recently I partially reimplemented SwiftForth's [BUF BUF] words for
VFX and for iForth. With these words, in iForth:
: call-emacs ( c-addr u line column -- )
[BUF ." echo emacs +" swap 0 .r ." :" . type BUF]
@BUF system ;
s" blah" 10 33 call-emacs
Outputs:
emacs +10:33 blah
This only required vectorable EMIT and TYPE from the system:
'emit @ constant 'orig-emit
'type @ constant 'orig-type
$8000 buffer: buf
variable BP
: buf-emit ( c -- )
BP @ c! BP ++ ;
: buf-type ( c-addr u -- )
BP @ swap dup BP +! move ;
: [buf ( -- )
buf BP !
['] buf-emit 'emit !
['] buf-type 'type ! ;
: buf] ( -- )
'orig-emit 'emit !
'orig-type 'type ! ;
: @buf ( -- c-addr u )
buf BP @ over - ;
Disadvantages:
1. 'buffered' code can't call a word that uses these words
as well to buffer some output, with more hassle. This works
automatically with >STRING-EXECUTE
2. There's no standard so this all had to be reimplemented. And the
lower level tools don't always have the same idea of how things should
work. My VFX code reused VFX's own buffered-text library and this was
probably a bad idea vs. just revectoring two words.
3. it's not as visually neat as a quotation and >STRING-EXECUTE
4. It uses a fixed buffer.
Advantages:
1. all of these implementations use a fixed buffer. How can I limit
>STRING-EXECUTE's memory use?
2. with all of them it's easy to open the code up and extend it to
f.e. auto-flush the buffer to stdout after a point, or to push the
buffer to a stack, or to truncate buffered I/O after a point, or even
to 'scroll' the buffer and keep only what's most recently emitted.
>STRING-EXECUTE is a black box.
3. You can interrupt and resume the buffering from within a buffered
expression.
: .headers ]BUF @BUF TYPE [BUF ;
...
: go [BUF generate-lots-of-output BUF] ;
-- Julian
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-12-07 17:50 +0000 |
| Message-ID | <2016Dec7.185020@mips.complang.tuwien.ac.at> |
| In reply to | #53157 |
Julian Fondren <julian.fondren@gmail.com> writes:
>On Wednesday, December 7, 2016 at 6:51:46 AM UTC-6, Anton Ertl wrote:
>> While we are at the topic of >STRING-EXECUTE: Another thing it is good
>> for is for constructing strings programmatically. E.g., do something
>> like (untested)
>>
>> : call-emacs ( c-addr u line column -- )
>> [: ." emacs +" swap 0 .r ." :" 0 .r space type ;] >string-execute
>> 2dup system free throw ;
>>
>> Try to write that without >STRING-EXECUTE, and see how much code would
>> be needed.
>
>Recently I partially reimplemented SwiftForth's [BUF BUF] words for
>VFX and for iForth. With these words, in iForth:
>
> : call-emacs ( c-addr u line column -- )
> [BUF ." echo emacs +" swap 0 .r ." :" . type BUF]
> @BUF system ;
That's a (probably much older) variation of the same idea.
>This only required vectorable EMIT and TYPE from the system:
>
> 'emit @ constant 'orig-emit
> 'type @ constant 'orig-type
>
> $8000 buffer: buf
> variable BP
>
> : buf-emit ( c -- )
> BP @ c! BP ++ ;
>
> : buf-type ( c-addr u -- )
> BP @ swap dup BP +! move ;
>
> : [buf ( -- )
> buf BP !
> ['] buf-emit 'emit !
> ['] buf-type 'type ! ;
>
> : buf] ( -- )
> 'orig-emit 'emit !
> 'orig-type 'type ! ;
>
> : @buf ( -- c-addr u )
> buf BP @ over - ;
>
>Disadvantages:
>
>1. 'buffered' code can't call a word that uses these words
>as well to buffer some output, with more hassle. This works
>automatically with >STRING-EXECUTE
I guess you can do the same for the [BUF...BUF] syntax, but the
implementation becomes more complicated, approaching that of
>STRING-EXECUTE.
>3. it's not as visually neat as a quotation and >STRING-EXECUTE
I guess there are people who will disagree:-).
5. An exception between [BUF and BUF] leaves EMIT and TYPE redirected.
>Advantages:
>
>1. all of these implementations use a fixed buffer. How can I limit
>>STRING-EXECUTE's memory use?
A fixed buffer is a disadvantage in my book. There is no provision
for limiting memory use by >STRING-EXECUTE. I considered an
alternative interface
>buffer-execute ( ... c-addr u1 xt -- ... u2 )
where you pass the buffer, and then the string would be naturally
limited to u1. But it's quite cumbersome to write programs that work
for all cases with such an interface (SUBSTITUTE is even worse), so I
did not implement it.
I just tried the buffer size limitation of SwiftForth:
: x [buf do space loop buf] ; 1000000000 0 x ok
@buf .s
184104108 1000000000 <-Top ok
works even with 2*10^9, but produces
Signal #11 at 08071D35 in (B-EMIT)
when I tried it with "3000000000 0 x"
@buf then outputs
169014444 -2147483647 <-Top
But that's a pretty natural limit for a 32-bit Forth system.
>2. with all of them it's easy to open the code up and extend it to
>f.e. auto-flush the buffer to stdout after a point, or to push the
>buffer to a stack, or to truncate buffered I/O after a point, or even
>to 'scroll' the buffer and keep only what's most recently emitted.
>>STRING-EXECUTE is a black box.
You can also look in the implementation of >STRING-EXECUTE, and derive
such variations from it if you want.
>3. You can interrupt and resume the buffering from within a buffered
>expression.
>
> : .headers ]BUF @BUF TYPE [BUF ;
> ...
> : go [BUF generate-lots-of-output BUF] ;
You lost me here.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2016-12-07 15:23 +0100 |
| Message-ID | <o2960a$ckk$1@cherry.spenarnc.xs4all.nl> |
| In reply to | #53152 |
In article <2016Dec7.121119@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>josv@planet.nl writes:
>>Hi,
>>Thank you, that is much better!
>>>string-execute is indeed very powerful.
>>When I use it for my needs I get:
>>
>>: f.73 ( r -- ) 7 3 0 f.rdp ;
>>: (f.73) ( r -- ) ( -- c-addr u ) ['] f.73 >string-execute ;
>
> >STRING-EXECUTE is orginally meant to make printing words like
>F. more flexible. In the present case, we have a variant that outputs
>to a string, so you could define the above as
>
>: (f.73) ( r -- c-addr u ) 7 3 0 f>str-rdp ;
>: f.73 ( r -- ) (f.73) type ;
>
>There is a behavioural difference: F>STR-RDP puts its result in the
>pictured numeric output buffer, and it is overwritten by the next use
>of that buffer, while >STRING-EXECUTE ALLOCATEs the buffer for the
>output string, and you have to FREE it yourself.
>
>From the implementation POV, F.RDP is implemented as
>
>: f.rdp f>str-rdp type ;
>
>so then undoing the TYPE by using >STRING-EXECUTE is not the most
>efficient way.
>
>While we are at the topic of >STRING-EXECUTE: Another thing it is good
>for is for constructing strings programmatically. E.g., do something
>like (untested)
>
>: call-emacs ( c-addr u line column -- )
> [: ." emacs +" swap 0 .r ." :" 0 .r space type ;] >string-execute
> 2dup system free throw ;
>
>Try to write that without >STRING-EXECUTE, and see how much code would
>be needed.
Other Forths have different tools evailable, e.g. ciforth:
WANT FORMAT&EVAL
: call-emacs ( c-addr u line column -- )
" ""emacs +%d :%d %s "" SYSTEM" FORMAT&EVAL ;
Without the eval
"AAP" 1 2 cal-emacs
yields
"emacs +2:1 AAP" SYSTEM
>
>- anton
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-12-08 16:18 +0000 |
| Message-ID | <2016Dec8.171827@mips.complang.tuwien.ac.at> |
| In reply to | #53158 |
albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) writes:
>In article <2016Dec7.121119@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>While we are at the topic of >STRING-EXECUTE: Another thing it is good
>>for is for constructing strings programmatically. E.g., do something
>>like (untested)
>>
>>: call-emacs ( c-addr u line column -- )
>> [: ." emacs +" swap 0 .r ." :" 0 .r space type ;] >string-execute
>> 2dup system free throw ;
>>
>>Try to write that without >STRING-EXECUTE, and see how much code would
>>be needed.
>
>Other Forths have different tools evailable, e.g. ciforth:
>
>WANT FORMAT&EVAL
>
>: call-emacs ( c-addr u line column -- )
> " ""emacs +%d :%d %s "" SYSTEM" FORMAT&EVAL ;
Good enough for the present case. However, this kind of macro
expansion is too inflexible if significant control flow occurs in the
xt passed to >string-execute. E.g., consider
: .tree {: node -- :} recursive
dup if
node node-label 2@ type ." ("
node node-left @ .tree ." ,"
node node-right @ .tree ." )"
then ;
some-tree ' .tree >string-execute
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | josv@planet.nl |
|---|---|
| Date | 2016-12-07 06:46 -0800 |
| Message-ID | <20685425-63df-42c4-aadc-60f4f6de240c@googlegroups.com> |
| In reply to | #53152 |
Thank you. f>str-rdp is indeed better for me. I am now just using: : (f.72) ( r -- ) ( -- c-addr u ) 7 2 0 f>str-rdp ; The definition of call-emacs is not entirely clear. s" test " 4 10 call-emacs puts me in Emacs It seems the same as: s" emacs test" system But I think there could be more in call-emacs. Jos On 7 december 2016 13:51:46 UTC+1 Anton Ertl wrote: > jo....nl writes: > >Hi, > >Thank you, that is much better! > >>string-execute is indeed very powerful. > >When I use it for my needs I get: > > > >: f.73 ( r -- ) 7 3 0 f.rdp ; > >: (f.73) ( r -- ) ( -- c-addr u ) ['] f.73 >string-execute ; > > >STRING-EXECUTE is orginally meant to make printing words like > F. more flexible. In the present case, we have a variant that outputs > to a string, so you could define the above as > > : (f.73) ( r -- c-addr u ) 7 3 0 f>str-rdp ; > : f.73 ( r -- ) (f.73) type ; > > There is a behavioural difference: F>STR-RDP puts its result in the > pictured numeric output buffer, and it is overwritten by the next use > of that buffer, while >STRING-EXECUTE ALLOCATEs the buffer for the > output string, and you have to FREE it yourself. > > From the implementation POV, F.RDP is implemented as > > : f.rdp f>str-rdp type ; > > so then undoing the TYPE by using >STRING-EXECUTE is not the most > efficient way. > > While we are at the topic of >STRING-EXECUTE: Another thing it is good > for is for constructing strings programmatically. E.g., do something > like (untested) > > : call-emacs ( c-addr u line column -- ) > [: ." emacs +" swap 0 .r ." :" 0 .r space type ;] >string-execute > 2dup system free throw ; > > Try to write that without >STRING-EXECUTE, and see how much code would > be needed. > > - anton > -- > M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html > comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html > New standard: http://www.forth200x.org/forth200x.html > EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-12-07 17:41 +0000 |
| Message-ID | <2016Dec7.184144@mips.complang.tuwien.ac.at> |
| In reply to | #53159 |
josv@planet.nl writes:
>The definition of call-emacs is not entirely clear.
>s" test " 4 10 call-emacs
>puts me in Emacs
>
>It seems the same as: s" emacs test" system
emacs +4:10 test
starts emacs, opens the file test, and puts the cursor in line 4,
column 10. "emacs test" puts the cursor at the start of the file.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-12-06 10:34 -0800 |
| Message-ID | <c8e5d86d-bf59-4951-ac61-9d3c66b6a47e@googlegroups.com> |
| In reply to | #53117 |
On Tuesday, December 6, 2016 at 4:40:16 AM UTC-7, jo...@planet.nl wrote:
> \ (f.) Makes it very easy to send a floating point number to some target.
> \ After looking to f. I now use the following code:
>
> : +pad ( adr cnt -- ) pad +place ;
>
> : f$ ( f -- n )
> pad off scratch represent 0=
> if 2drop scratch 3 min +pad rdrop exit then
> if s" -" +pad then ;
>
> : (f.) ( r -- ) ( -- adr cnt )
> \G Writes (the floating-point number) @i{r} without exponent,
> \G to a string. Includes last zeros when needed.
> f$ dup >r 0<=
> if s" 0" +pad
> else scratch r@ min +pad r@ precision - zeros
> then
> s" ." +pad r@ negate zeros
> scratch r> 0 max /string 0 max
> +pad pad count ;
>
> \ Eg:
> : crf. ( f - ) cr (f.) type ;
> 7 set-precision
> -12.3e crf. -1.003e crf.
> -1.3e crf. 0e crf.
>
> \\\ Output
> -12.30000
> -1.003000
> -1.300000
> 0.000000 ok
> \ Jos
I have this in the novice-package:
---------------------------------------------------------------------------
: comma ( d -- d )
[char] , hold ;
: dot ( d -- d )
[char] . hold ;
: _# ( d -- d_less_digit ) \ digit if number is non-zero, else a blank
2dup d0= if bl hold else # then ;
: _comma ( d -- d ) \ comma if number is non-zero, else a blank
2dup d0= if bl hold else comma then ;
\ _# and _comma are used to blank-out the leftmost of the number if the digits are zero.
: book-sign ( d neg? -- d )
if [char] - else [char] + then hold ;
\ This is a bookkeeping-style sign. It prints a + for positive rather than print nothing.
item sgn \ used by ?#
: ?# ( d -- new-d ) \ needs SGN set \ similar to _# except puts a - in there if SGN is set
2dup d0= if
sgn if sgn sign else bl hold then
false to sgn
else
# then ;
: ?comma ( d -- d ) \ needs SGN set \ similar to _comma except puts a - in there if SGN is set
2dup d0= if
sgn if sgn sign else bl hold then
false to sgn
else
comma then ;
: <big.> ( d -- adr cnt ) \ used for big numbers that need commas for clarity
2dup d0< to sgn dabs
<#
# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?#
#> ;
: big. ( d -- )
<big.> type ;
item ~#soft \ TRUE implies that ~# shouldn't output zeros
: ~# ( Da -- Db ) \ needs ~#SOFT set
~#soft if
2dup 10 um/mod drop if # false to ~#soft
else 1 10 m*/ then
else
# then ;
: ~. ( D -- D ) \ needs ~#SOFT set
~#soft not if [char] . hold then ;
\ ~# is used for the digits to the right of the decimal point.
\ ~. is used for the decimal point.
: round-off { prec -- } \ float: n -- new-n
prec 1 ?do 10.e f* loop fnear
prec 1 ?do 10.e f/ loop ;
: adjust-down ( adjustment -- new-adjustment ) \ float: n -- new-n
begin fdup 10.e f>= while
10.e f/ 1+ repeat ;
: adjust-up ( adjustment -- new-adjustment ) \ float: n -- new-n
begin fdup 1.e f< while
10.e f* 1- repeat ;
: exponent { prec | sgn -- adjustment } \ float: n -- new-n
0 \ -- adjustment
fdup f0= if exit then
fdup f0< to sgn fabs
adjust-up
adjust-down prec round-off adjust-down
sgn if fnegate then ;
: #exponent ( n -- ) \ must be called from within <# #>
?dup if
dup >r abs 0 \ -- d
#s r> sign [char] e hold \ -- d0
2drop then ;
: <scientific> { prec engineering? | sgn exp -- adr cnt } \ float: n --
prec 1 < abort" *** F>STRING needs a precision parameter >= 1 ***"
prec exponent to exp
engineering? if
begin exp 3 mod while 10.e f* -1 +to exp -1 +to prec repeat
fdup fabs prec round-off
1000.e f>= if 1000.e f/ 3 +to exp 3 +to prec then
then
prec 1 ?do 10.e f* loop
fnear f>d
dup to sgn dabs <# bl hold
exp #exponent
true to ~#soft prec 1 ?do ~# loop ~.
2dup or if #s
else ~#soft if #s then then
sgn sign #> ;
\ The e is optional, which prevents these numbers from being used in Forth source-code. >FLOAT still works though.
10 constant max-prec \ 11 works sometmes, but fails if the most significant digit is large. 10 always works.
: scientific ( -- adr cnt ) \ float: n --
precision false <scientific> ;
: max-scientific ( -- adr cnt ) \ float: n --
max-prec false <scientific> ;
: engineering ( -- adr cnt ) \ float: n --
precision true <scientific> ;
: max-engineering ( -- adr cnt ) \ float: n --
max-prec true <scientific> ;
: HOLDS ( adr len -- ) \ HOLD a string
BEGIN DUP WHILE 1- 2DUP CHARS + C@ HOLD REPEAT 2DROP ;
\ HOLDS was written by HAA (he called it $HOLD though): https://groups.google.com/forum/#!topic/comp.lang.forth/ictps0w02yk
---------------------------------------------------------------------------
[toc] | [prev] | [next] | [standalone]
| From | josv@planet.nl |
|---|---|
| Date | 2016-12-09 12:11 -0800 |
| Message-ID | <6a0e020f-2cca-4de7-9fcd-fa66f3ca75e3@googlegroups.com> |
| In reply to | #53135 |
That is quite a lot.
More thinking about the subject left me with:
: (f.2) ( f -- ) ( -- c-addr u )
100e f* f>d tuck dabs <# # # [char] . hold #s rot sign #> ;
Just for small numbers.
Jos
On 6 december 2016 19:34:55 UTC+1 hughag...@gmail.com wrote:
> On Tuesday, December 6, 2016 at 4:40:16 AM UTC-7, jo...@planet.nl wrote:
> > \ (f.) Makes it very easy to send a floating point number to some target.
> > \ After looking to f. I now use the following code:
> >
> > : +pad ( adr cnt -- ) pad +place ;
> >
> > : f$ ( f -- n )
> > pad off scratch represent 0=
> > if 2drop scratch 3 min +pad rdrop exit then
> > if s" -" +pad then ;
> >
> > : (f.) ( r -- ) ( -- adr cnt )
> > \G Writes (the floating-point number) @i{r} without exponent,
> > \G to a string. Includes last zeros when needed.
> > f$ dup >r 0<=
> > if s" 0" +pad
> > else scratch r@ min +pad r@ precision - zeros
> > then
> > s" ." +pad r@ negate zeros
> > scratch r> 0 max /string 0 max
> > +pad pad count ;
> >
> > \ Eg:
> > : crf. ( f - ) cr (f.) type ;
> > 7 set-precision
> > -12.3e crf. -1.003e crf.
> > -1.3e crf. 0e crf.
> >
> > \\\ Output
> > -12.30000
> > -1.003000
> > -1.300000
> > 0.000000 ok
> > \ Jos
>
> I have this in the novice-package:
> ---------------------------------------------------------------------------
>
> : comma ( d -- d )
> [char] , hold ;
>
> : dot ( d -- d )
> [char] . hold ;
>
> : _# ( d -- d_less_digit ) \ digit if number is non-zero, else a blank
> 2dup d0= if bl hold else # then ;
>
> : _comma ( d -- d ) \ comma if number is non-zero, else a blank
> 2dup d0= if bl hold else comma then ;
>
> \ _# and _comma are used to blank-out the leftmost of the number if the digits are zero.
>
> : book-sign ( d neg? -- d )
> if [char] - else [char] + then hold ;
>
> \ This is a bookkeeping-style sign. It prints a + for positive rather than print nothing.
>
> item sgn \ used by ?#
>
> : ?# ( d -- new-d ) \ needs SGN set \ similar to _# except puts a - in there if SGN is set
> 2dup d0= if
> sgn if sgn sign else bl hold then
> false to sgn
> else
> # then ;
>
> : ?comma ( d -- d ) \ needs SGN set \ similar to _comma except puts a - in there if SGN is set
> 2dup d0= if
> sgn if sgn sign else bl hold then
> false to sgn
> else
> comma then ;
>
> : <big.> ( d -- adr cnt ) \ used for big numbers that need commas for clarity
> 2dup d0< to sgn dabs
> <#
> # ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?#
> #> ;
>
> : big. ( d -- )
> <big.> type ;
>
> item ~#soft \ TRUE implies that ~# shouldn't output zeros
>
> : ~# ( Da -- Db ) \ needs ~#SOFT set
> ~#soft if
> 2dup 10 um/mod drop if # false to ~#soft
> else 1 10 m*/ then
> else
> # then ;
>
> : ~. ( D -- D ) \ needs ~#SOFT set
> ~#soft not if [char] . hold then ;
>
> \ ~# is used for the digits to the right of the decimal point.
> \ ~. is used for the decimal point.
>
> : round-off { prec -- } \ float: n -- new-n
> prec 1 ?do 10.e f* loop fnear
> prec 1 ?do 10.e f/ loop ;
>
> : adjust-down ( adjustment -- new-adjustment ) \ float: n -- new-n
> begin fdup 10.e f>= while
> 10.e f/ 1+ repeat ;
>
> : adjust-up ( adjustment -- new-adjustment ) \ float: n -- new-n
> begin fdup 1.e f< while
> 10.e f* 1- repeat ;
>
> : exponent { prec | sgn -- adjustment } \ float: n -- new-n
> 0 \ -- adjustment
> fdup f0= if exit then
> fdup f0< to sgn fabs
> adjust-up
> adjust-down prec round-off adjust-down
> sgn if fnegate then ;
>
> : #exponent ( n -- ) \ must be called from within <# #>
> ?dup if
> dup >r abs 0 \ -- d
> #s r> sign [char] e hold \ -- d0
> 2drop then ;
>
> : <scientific> { prec engineering? | sgn exp -- adr cnt } \ float: n --
> prec 1 < abort" *** F>STRING needs a precision parameter >= 1 ***"
> prec exponent to exp
> engineering? if
> begin exp 3 mod while 10.e f* -1 +to exp -1 +to prec repeat
> fdup fabs prec round-off
> 1000.e f>= if 1000.e f/ 3 +to exp 3 +to prec then
> then
> prec 1 ?do 10.e f* loop
> fnear f>d
> dup to sgn dabs <# bl hold
> exp #exponent
> true to ~#soft prec 1 ?do ~# loop ~.
> 2dup or if #s
> else ~#soft if #s then then
> sgn sign #> ;
>
> \ The e is optional, which prevents these numbers from being used in Forth source-code. >FLOAT still works though.
>
> 10 constant max-prec \ 11 works sometmes, but fails if the most significant digit is large. 10 always works.
>
> : scientific ( -- adr cnt ) \ float: n --
> precision false <scientific> ;
>
> : max-scientific ( -- adr cnt ) \ float: n --
> max-prec false <scientific> ;
>
> : engineering ( -- adr cnt ) \ float: n --
> precision true <scientific> ;
>
> : max-engineering ( -- adr cnt ) \ float: n --
> max-prec true <scientific> ;
>
> : HOLDS ( adr len -- ) \ HOLD a string
> BEGIN DUP WHILE 1- 2DUP CHARS + C@ HOLD REPEAT 2DROP ;
>
> \ HOLDS was written by HAA (he called it $HOLD though): https://groups.google.com/forum/#!topic/comp.lang.forth/ictps0w02yk
>
> ---------------------------------------------------------------------------
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-12-23 13:23 +1100 |
| Message-ID | <o3i1pr$1vpr$1@gioia.aioe.org> |
| In reply to | #53231 |
josv@planet.nl wrote: > That is quite a lot. > More thinking about the subject left me with: > > : (f.2) ( f -- ) ( -- c-addr u ) > 100e f* f>d tuck dabs <# # # [char] . hold #s rot sign #> ; > > Just for small numbers. > Jos > ... As cute as the above is, would you have bothered had ANS provided a functional (F.) and (FS.) and they were present in your float package? :)
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-12-15 15:42 -0800 |
| Message-ID | <bfcb425f-f509-44d7-a643-ea086645780c@googlegroups.com> |
| In reply to | #53135 |
On Tuesday, December 6, 2016 at 11:34:55 AM UTC-7, hughag...@gmail.com wrote:
> On Tuesday, December 6, 2016 at 4:40:16 AM UTC-7, jo...@planet.nl wrote:
> > \ (f.) Makes it very easy to send a floating point number to some target.
> > \ After looking to f. I now use the following code:
> >
> > : +pad ( adr cnt -- ) pad +place ;
> >
> > : f$ ( f -- n )
> > pad off scratch represent 0=
> > if 2drop scratch 3 min +pad rdrop exit then
> > if s" -" +pad then ;
> >
> > : (f.) ( r -- ) ( -- adr cnt )
> > \G Writes (the floating-point number) @i{r} without exponent,
> > \G to a string. Includes last zeros when needed.
> > f$ dup >r 0<=
> > if s" 0" +pad
> > else scratch r@ min +pad r@ precision - zeros
> > then
> > s" ." +pad r@ negate zeros
> > scratch r> 0 max /string 0 max
> > +pad pad count ;
> >
> > \ Eg:
> > : crf. ( f - ) cr (f.) type ;
> > 7 set-precision
> > -12.3e crf. -1.003e crf.
> > -1.3e crf. 0e crf.
> >
> > \\\ Output
> > -12.30000
> > -1.003000
> > -1.300000
> > 0.000000 ok
> > \ Jos
>
> I have this in the novice-package:
> ---------------------------------------------------------------------------
>
> : comma ( d -- d )
> [char] , hold ;
>
> : dot ( d -- d )
> [char] . hold ;
>
> : _# ( d -- d_less_digit ) \ digit if number is non-zero, else a blank
> 2dup d0= if bl hold else # then ;
>
> : _comma ( d -- d ) \ comma if number is non-zero, else a blank
> 2dup d0= if bl hold else comma then ;
>
> \ _# and _comma are used to blank-out the leftmost of the number if the digits are zero.
>
> : book-sign ( d neg? -- d )
> if [char] - else [char] + then hold ;
>
> \ This is a bookkeeping-style sign. It prints a + for positive rather than print nothing.
>
> item sgn \ used by ?#
>
> : ?# ( d -- new-d ) \ needs SGN set \ similar to _# except puts a - in there if SGN is set
> 2dup d0= if
> sgn if sgn sign else bl hold then
> false to sgn
> else
> # then ;
>
> : ?comma ( d -- d ) \ needs SGN set \ similar to _comma except puts a - in there if SGN is set
> 2dup d0= if
> sgn if sgn sign else bl hold then
> false to sgn
> else
> comma then ;
>
> : <big.> ( d -- adr cnt ) \ used for big numbers that need commas for clarity
> 2dup d0< to sgn dabs
> <#
> # ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?# ?# ?# ?comma
> ?#
> #> ;
>
> : big. ( d -- )
> <big.> type ;
>
> item ~#soft \ TRUE implies that ~# shouldn't output zeros
>
> : ~# ( Da -- Db ) \ needs ~#SOFT set
> ~#soft if
> 2dup 10 um/mod drop if # false to ~#soft
> else 1 10 m*/ then
> else
> # then ;
>
> : ~. ( D -- D ) \ needs ~#SOFT set
> ~#soft not if [char] . hold then ;
>
> \ ~# is used for the digits to the right of the decimal point.
> \ ~. is used for the decimal point.
>
> : round-off { prec -- } \ float: n -- new-n
> prec 1 ?do 10.e f* loop fnear
> prec 1 ?do 10.e f/ loop ;
>
> : adjust-down ( adjustment -- new-adjustment ) \ float: n -- new-n
> begin fdup 10.e f>= while
> 10.e f/ 1+ repeat ;
>
> : adjust-up ( adjustment -- new-adjustment ) \ float: n -- new-n
> begin fdup 1.e f< while
> 10.e f* 1- repeat ;
>
> : exponent { prec | sgn -- adjustment } \ float: n -- new-n
> 0 \ -- adjustment
> fdup f0= if exit then
> fdup f0< to sgn fabs
> adjust-up
> adjust-down prec round-off adjust-down
> sgn if fnegate then ;
>
> : #exponent ( n -- ) \ must be called from within <# #>
> ?dup if
> dup >r abs 0 \ -- d
> #s r> sign [char] e hold \ -- d0
> 2drop then ;
>
> : <scientific> { prec engineering? | sgn exp -- adr cnt } \ float: n --
> prec 1 < abort" *** F>STRING needs a precision parameter >= 1 ***"
> prec exponent to exp
> engineering? if
> begin exp 3 mod while 10.e f* -1 +to exp -1 +to prec repeat
> fdup fabs prec round-off
> 1000.e f>= if 1000.e f/ 3 +to exp 3 +to prec then
> then
> prec 1 ?do 10.e f* loop
> fnear f>d
> dup to sgn dabs <# bl hold
> exp #exponent
> true to ~#soft prec 1 ?do ~# loop ~.
> 2dup or if #s
> else ~#soft if #s then then
> sgn sign #> ;
>
> \ The e is optional, which prevents these numbers from being used in Forth source-code. >FLOAT still works though.
>
> 10 constant max-prec \ 11 works sometmes, but fails if the most significant digit is large. 10 always works.
>
> : scientific ( -- adr cnt ) \ float: n --
> precision false <scientific> ;
>
> : max-scientific ( -- adr cnt ) \ float: n --
> max-prec false <scientific> ;
>
> : engineering ( -- adr cnt ) \ float: n --
> precision true <scientific> ;
>
> : max-engineering ( -- adr cnt ) \ float: n --
> max-prec true <scientific> ;
>
> : HOLDS ( adr len -- ) \ HOLD a string
> BEGIN DUP WHILE 1- 2DUP CHARS + C@ HOLD REPEAT 2DROP ;
>
> \ HOLDS was written by HAA (he called it $HOLD though): https://groups.google.com/forum/#!topic/comp.lang.forth/ictps0w02yk
>
> ---------------------------------------------------------------------------
I post code that works, as shown above.
Andrew Haley, Julien Fondren and Anton Ertl blow great quantities of hot air on the subject of pragmatism.
So, who knows more about pragmatism? LOL
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-12-07 13:06 +1100 |
| Message-ID | <o27qqu$alb$1@gioia.aioe.org> |
| In reply to | #53117 |
josv@planet.nl wrote:
> \ (f.) Makes it very easy to send a floating point number to some target.
An early ANS draft had (F.) and (E.). Had they gone with it you wouldn't
now be looking for a solution for what every other language provides :)
12.1.0084 (F.) "Paren-f-dot-paren"
( -- c-addr u )( F: r -- ) or ( r -- c-addr u )
Convert the top number on the floating-point stack to its character
string representation using fixed point notation:
[-] <digit>.<digits0>
The number of digits after the decimal point is determined by PLACES.
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-12-06 18:32 -0800 |
| Message-ID | <57548000-b756-4f8b-ac69-6e3fb4be4f7e@googlegroups.com> |
| In reply to | #53145 |
On Tuesday, December 6, 2016 at 7:06:28 PM UTC-7, HAA wrote: > josv@planet.nl wrote: > > \ (f.) Makes it very easy to send a floating point number to some target. > > An early ANS draft had (F.) and (E.). Had they gone with it you wouldn't > now be looking for a solution for what every other language provides :) > > 12.1.0084 (F.) "Paren-f-dot-paren" > ( -- c-addr u )( F: r -- ) or ( r -- c-addr u ) > > Convert the top number on the floating-point stack to its character > string representation using fixed point notation: > [-] <digit>.<digits0> > The number of digits after the decimal point is determined by PLACES. Well, I have both scientific and engineering format --- if ANS-Forth had gone with that, they would have still been weak --- even a half-hearted effort though, is better than no effort, which is what became the Standard. In my output the 'e' doesn't get generated unless there is an exponent, so my output can't be used directly in ANS-Forth source-code --- my STR>NUM in the string-stack.4th package works with my output though --- so does >FLOAT that is ANS-Forth. Something like STR>NUM will be used in Straight Forth's outer-interpreter --- I won't have that ridiculous ANS-Forth scheme in which a dot indicates a double-precision integer and floats have to have the 'e' --- I want it to be easy for a programmer to write a Straight Forth program that generates Straight Forth source-code, or C source-code, or FASM source-code, etc.. Making it easy for Forth programs to generate source-code for Straight Forth and other languages seems obvious, but apparently didn't occur to the ANS-Forth committee. Pretty much everything in Straight Forth seems obvious -- I'm not trying to be clever --- I'm just applying some common-sense and basic programming knowledge.
[toc] | [prev] | [next] | [standalone]
| From | albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2016-12-07 12:41 +0100 |
| Message-ID | <o28sh1$b7g$1@cherry.spenarnc.xs4all.nl> |
| In reply to | #53146 |
In article <57548000-b756-4f8b-ac69-6e3fb4be4f7e@googlegroups.com>, <hughaguilar96@gmail.com> wrote: >On Tuesday, December 6, 2016 at 7:06:28 PM UTC-7, HAA wrote: >> josv@planet.nl wrote: >> > \ (f.) Makes it very easy to send a floating point number to some targe= >t. >>=20 >> An early ANS draft had (F.) and (E.). Had they gone with it you wouldn't >> now be looking for a solution for what every other language provides :) >>=20 >> 12.1.0084 (F.) "Paren-f-dot-paren" >> ( -- c-addr u )( F: r -- ) or ( r -- c-addr u ) >>=20 >> Convert the top number on the floating-point stack to its character >> string representation using fixed point notation: >> [-] <digit>.<digits0> >> The number of digits after the decimal point is determined by PLACES. > >Well, I have both scientific and engineering format --- if ANS-Forth had go= >ne with that, they would have still been weak --- even a half-hearted effor= >t though, is better than no effort, which is what became the Standard. > >In my output the 'e' doesn't get generated unless there is an exponent, so = >my output can't be used directly in ANS-Forth source-code --- my STR>NUM in= > the string-stack.4th package works with my output though --- so does >FLOA= >T that is ANS-Forth. > My ideal : I'd deemphasis double numbers and require that they must be preceeded *and* ended with a dot (which is now of course not a decimal point.) .170141183460469231731687303715884105727. Regards floating point: The exponent sign must *not* be a hex number, preferred are _ or ~ or simple the sign of the exponent. Any number that has either a decimal point or an exponent sign is floating point: 1. 1_0 3.145_0 1.-19 Maybe : 3.17+20 1+100 Two fp number separated by / are complex: : i 0./1. ; Going as far as portability tolerates: in ciforth I change the exponent sign to _ , as soon as BASE is not DECIMAL . Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-12-07 19:49 -0800 |
| Message-ID | <edb9659b-680c-4d2d-9ef3-7fc2a019305c@googlegroups.com> |
| In reply to | #53151 |
On Wednesday, December 7, 2016 at 4:30:31 AM UTC-7, Albert van der Horst wrote:
> In article <57548000-b756-4f8b-ac69-6e3fb4be4f7e@googlegroups.com>,
> <hughaguilar96@gmail.com> wrote:
> > ...
What I said, which you snipped, was this:
On Tuesday, December 6, 2016 at 7:32:07 PM UTC-7, hughag...@gmail.com wrote:
> Something like STR>NUM will be used in Straight Forth's outer-interpreter --- I won't have that ridiculous ANS-Forth scheme in which a dot indicates a double-precision integer and floats have to have the 'e' --- I want it to be easy for a programmer to write a Straight Forth program that generates Straight Forth source-code, or C source-code, or FASM source-code, etc..
>
> Making it easy for Forth programs to generate source-code for Straight Forth and other languages seems obvious, but apparently didn't occur to the ANS-Forth committee. Pretty much everything in Straight Forth seems obvious -- I'm not trying to be clever --- I'm just applying some common-sense and basic programming knowledge.
> My ideal :
>
> I'd deemphasis double numbers and require that they must be preceeded *and*
> ended with a dot (which is now of course not a decimal point.)
> .170141183460469231731687303715884105727.
No other language does this, so you can't generate source-code for any other language, which I described as being an "obvious" feature needed.
Also, you aren't compatible with ANS-Forth, and Forth-200x is mandated to be 100% compatible with ANS-Forth --- if you are going to be incompatible with ANS-Forth, you might as well go with my Straight Forth design that is incompatible with ANS-Forth but has useful features.
> Regards floating point:
> The exponent sign must *not* be a hex number, preferred are _ or ~ or simple
> the sign of the exponent.
Other languages use some kind of prefix or suffix to indicate hexadecimal --- we have $ in Pascal and 0x in C.
Abandoning fantasy and getting back to the subject of my working Forth in the novice package, here is a demonstration:
123456789123456.789e ok F:-1
fdup engineering type 123.45679e12 ok F:-1
fdup scientific type 1.2345679e14 ok F:-1
Once again, here is a snippet of the code:
10 constant max-prec \ 11 works sometmes, but fails if the most significant digit is large. 10 always works.
: scientific ( -- adr cnt ) \ float: n --
precision false <scientific> ;
: max-scientific ( -- adr cnt ) \ float: n --
max-prec false <scientific> ;
: engineering ( -- adr cnt ) \ float: n --
precision true <scientific> ;
: max-engineering ( -- adr cnt ) \ float: n --
max-prec true <scientific> ;
SCIENTIFIC and ENGINEERING used PRECISION for how many digits are displayed. It is also possible to provide this value explicitly because <SCIENTIFIC> takes it as a parameter. I don't really like PRECISION because it is not reentrant, and I am making my novice-package reentrant as much as possible. The ANS-Forth document (12.6.2.2035 and 12.6.2.2200) doesn't indicate if the PRECISION value is a user-variable or not --- IIRC, the ANS-Forth document makes no mention of user variables at all.
> Any number that has either a decimal point or an exponent sign is
> floating point:
> 1. 1_0 3.145_0 1.-19
> Maybe : 3.17+20 1+100
>
> Two fp number separated by / are complex:
> : i 0./1. ;
In Straight Forth I have ratios --- a number such as 1/2 would be equivalent to 0.5 --- you are being over-creative with your syntax!
> Going as far as portability tolerates:
> in ciforth I change the exponent sign to _ , as soon as BASE is not
> DECIMAL .
Still being over-creative with your syntax. No other language uses _ in numbers --- that is really going to baffle everybody --- and it is not helping us to generate source-code for other languages.
It is true that some old math books use _ instead of , after every third digit in big numbers; they did this because the print quality of the books was bad and the readers couldn't distinguish between a , and a . without using a magnifying glass --- this is irrelevent though --- nobody has ever done this in software; it was only an issue with printed books given 1970s book-printing technology.
Anyway, you are just being over-creative. This is one of the reasons why Forth has a reputation for being hard-to-read --- gratuitous creativity minus common-sense equals weirdness --- how is that for a math equation?
Getting back to the subject of my string-stack.4th package, here is an excerpt:
\ STR>INT converts strings to integers, either singles and doubles.
\ An integer is a string of digits. There may be commas throughout.
\ An integer may have a $ # or % at the front, signifying that it is hexadecimal, decimal or binary. If none of these are present, then BASE is used.
\ An integer may have a + or - at the front (after the base signifier if there is one), signifying non-negative or negative, but otherwise it is non-negative.
\ A comma at the beginning (after the sign signifier if there is one) signifies that the integer is a double, but otherwise it is a single.
\ These are valid integers:
\ $-,123,456 double: -123456 hexadecimal
\ -,123,456 double: -123456
\ ,123,456 double: 123456
\ 123,456 single: 123456
\ STR>FLT converts strings to floats.
\ A float is a string of digits. There may be commas throughout. All floats are in decimal.
\ A comma in the front is legal but should not be used as STR>NUM will interpret this as an invalid double.
\ There must be either a decimal-point or an exponent-signifier (either 'E' or 'e') or both.
\ If there is a decimal-point, there must be digits either before or after or both.
\ The first digits are the integer part. The digits after the decimal-point, if there is a decimal-point, are the fraction part.
\ The digits after the exponent-signifier, if there is an exponent-signifier, are the exponent part (scientific notation).
\ If there is an exponent-signifier, there must be digits after it.
\ An exponent may have a + or - at the front, signifying non-negative or negative, but otherwise it is non-negative.
\ STR>NUM converts strings to either integers or floats.
\ These are valid floats:
\ -123,456.78 float: -123456.78
\ -123,456.78E4 float: -1234567800
\ -123,456.78E-4 float: -12.345678
\ 123E4 float: 1230000
[toc] | [prev] | [next] | [standalone]
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Date | 2016-12-08 08:12 +0000 |
| Message-ID | <o2b4iu$u2f$1@dont-email.me> |
| In reply to | #53182 |
On 08/12/2016 03:49, hughaguilar96@gmail.com wrote: > Other languages use some kind of prefix or suffix to indicate hexadecimal --- we have $ in Pascal and 0x in C. > Forth 2012/20XX has prefixes: # for decimal numbers $ for hex % for binary See section 3.4.1.3 in http://forth-standard.org/standard/usage -- Gerry
[toc] | [prev] | [next] | [standalone]
Page 1 of 8 [1] 2 3 4 5 6 7 8 Next page →
Back to top | Article view | comp.lang.forth
csiph-web