From: Timothy J. H. <ti...@cs...> - 2004-08-05 18:07:42
|
On Aug 5, 2004, at 12:57 PM, Geoffrey Knauth wrote: > Maybe this is a FAQ. I guess I was surprised I got 0 instead of #f > and/or an exception of some kind. > > $ java -cp lib/jscheme.jar jscheme.REPL > JScheme 7.1 (8/5/04 3:06 AM) http://jscheme.sourceforge.net > > (* 256 256 256 256) > 0 > > (* 256 256 256) > 16777216 > > (* 256 256 256 128) > -2147483648 > > I guess we need a FAQ for JScheme and questions about numerics need to be there... --------------------- Q: Why does integer arithemetic give numerically incorrect results in JScheme? A: JScheme numbers and operators are taken from Java so, for example, 256 in an "int" and hence raising 256 to the fourth power gives zero in JScheme > (display (* 256 256 256 256)) 0 This gives zero because it gives the same result as a corresponding Java program, such as the following: public class Demo { public static void main(String[] args) { int x = 256; System.out.println(x * x * x * x); } } Java integer arithmetic is does not throw exceptions on overflow and just returns the lower order 32 bits of the answer, hence you get 0 for If you want the Scheme numeric tower (which is an optional part of R4RS) you can import the SISC tower and use the siscnum.scm module described here: http://localhost:8080/jscheme/src/using/package.html However, if you use this you must explicity convert SISC numbers to Java numbers before using those numbers in javadot calls. ---Tim--- > > Geoffrey > -- > Geoffrey S. Knauth | http://knauth.org/gsk > > > > ------------------------------------------------------- > This SF.Net email is sponsored by OSTG. Have you noticed the changes on > Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, > one more big change to announce. We are now OSTG- Open Source > Technology > Group. Come see the changes on the new OSTG site. www.ostg.com > _______________________________________________ > Jscheme-devel mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-devel |