Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!samsung!uakari.primate.wisc.edu!sdd.hp.com!decwrl!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Mathematical routines Message-ID: <1464.UUL1.3#5129@willett.UUCP> Date: 6 Aug 90 03:28:23 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 59 Category 3, Topic 10 Message 48 Sun Aug 05, 1990 R.BERKEY [Robert] at 04:47 PDT Zafar Essak writes 900731: I am...creating an index to an existing catalogue of items that are numbered...Each number can be 5 digits with the first 3 signifying a major division and the right 2 digits signifying more specificity. 078.1 781 781.0 Unfortunately, a blank to the right of the number is different than a zero. Thus, "781_" is different from "7810". Is there some way of approaching these numbers as integers, even double numbers, without resorting to floating point? Base 36 looks as if it should work: $20 CONSTANT #SP : UM+ ( wd u -- wd ) 0 D+ ; : UM* ( ud u -- ud ) DUP>R * ( lo hi*u) SWAP R> U*D ROT + ; : 36IT ( & # -- ud ) \ make the index 0, 2SWAP BOUNDS DO #36 UM* I C@ #SP - UM+ LOOP ; : .IT ( d -- ) \ display the index <# BEGIN #36 MU/MOD ROT ( d rem) #SP + HOLD ( d) 2DUP D0= UNTIL #> ( & #) 5 OVER - 0 MAX SPACES \ print leading spaces TYPE ; " 078.1" 36it .it 078.1 ok " 781 " 36it .it 781 ok " 781.0" 36it .it 781.0 ok " 78.1" 36it .it 78.1 ok " 99999" 36it .it 99999 ok Robert ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu