Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34573
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Why I like Forth |
| Date | 2014-11-23 13:29 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2014Nov23.142910@mips.complang.tuwien.ac.at> (permalink) |
| References | <87d988fc-26c2-492c-8e51-f0ede5758a69@googlegroups.com> |
mhx@iae.nl writes:
>========================================
>Scilab 5.5.0 (Apr 11 2014, 12:13:09)
>
>-->abs(int8(-128))
> ans =
>
> -128
>========================================
>marcel@me-tarzan ~
>$ echo "int main (void) { char a=-128; return printf("%d",abs(a)); }" > a.c; gcc a.c 2&>err; ./a
>128
>========================================
>iForth version 4.0.1782, generated 21:06:07, March 6, 2014.
>x86_64 binary, native floating-point, extended precision.
>Copyright 1996 - 2014 Marcel Hendrix.
>
>FORTH> -128 $FF AND abs . 128 ok
>========================================
And your point is?
ABS does not always produce a "positive" number even in Forth (and C):
-9223372036854775808 abs . -9223372036854775808 ok
However, one can consider "ABS ." to be a type error. If you improve
this to
-9223372036854775808 abs u.
you get the right result (on a 64-bit system). The difference in type
definitions between Forth and C is interesting, though:
|6.1.0690 ABS abs CORE ( n -- u )
vs.
|int abs(int j);
|Trying to take the absolute value of the most negative integer is not
|defined.
- 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 2014: http://www.euroforth.org/ef14/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why I like Forth mhx@iae.nl - 2014-11-23 02:45 -0800
Re: Why I like Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-11-23 13:29 +0000
Re: Why I like Forth mhx@iae.nl - 2014-11-23 06:58 -0800
Re: Why I like Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-11-23 15:28 +0000
Re: Why I like Forth Julian Fondren <julian.fondren@gmail.com> - 2014-11-23 09:55 -0800
Re: Why I like Forth "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-11-23 14:33 -0500
Re: Why I like Forth Julian Fondren <julian.fondren@gmail.com> - 2014-11-23 12:35 -0800
Re: Why I like Forth mhx@iae.nl - 2014-11-23 13:23 -0800
csiph-web