Path: utzoo!attcan!uunet!mcsun!sunic!ifi!m2cs.uu.no!tomas From: tomas@m2cs.uu.no (Tomas Felner) Newsgroups: comp.windows.news Subject: Re: Integers, mod, and some wallpaper patches Message-ID: <1989Nov6.075307.10547@m2cs.uu.no> Date: 6 Nov 89 07:53:07 GMT References: <28574@sparkyfs.istc.sri.com> Organization: Modula-2 CASE Systems A/S, Oslo, Norway Lines: 38 zwicky@sparkyfs.itstd.sri.com (Elizabeth Zwicky) writes: >In particular, div and exp are both documented in the Red Book as >always returning reals. In NeWS, when div returns an integer, it is >type integer. This makes sense, given that the NeWS manual says that >any real small enough to be an integer (i.e., that will fit in 16 bits >of integer and 16 bits of fraction), will be an integer, which will >magically look like a real to type. So div should be returning a real, >which is small enough to be converted into an integer, which then gets >turned back into a real if it has a fractional part. Confusing, but >fine. That is, until you get to exp, which really truly does always >return a real; "2 2 exp dup = type =" will give you "4 realtype". What >a nusiance. >Next, we have mod and idiv, both of which are documented in the red >book as requiring integer arguments. mod does in fact require >arguments of type integer, and will return a typecheck if run on 2.4, >2 2 exp, or any number over 32767. idiv neither requires integer >arguments, *nor is guaranteed to return them*; try "2 17 exp 2 idiv >type =". I assume this is due to the magic conversion of integers to >reals once they get to big; on the other hand, since mod will return a >typecheck, it is not helpful. Then again, cvi does no better; try >"32768 cvi type =". Just what I wanted; a real result from converting >to an integer. And once again, mod will blow up. I once had a similar problem. Depending on how many zeros you have after the comma you get either a realtype or an integertype. Try the following: "1.0000 dup == type ==", you will get an integertype! If you type: "1.00000 dup == type ==" you will get a realtype!!! Now, which one is correct ?? Tomas -- Tomas Felner Modula-2 CASE Systems AS | Internet: tomas@m2cs.uu.no Maridalsveien 139 | Phone: +47 2 379784 N-0461 Oslo 4, Norway | FAX: +47 2 356448