home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.hp48
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!agate!iat.holonet.net!brianw
- From: brianw@iat.holonet.net (Brian Walsh)
- Subject: Re: Power of 2
- Message-ID: <Bz611z.Dw6@iat.holonet.net>
- Organization: HoloNet National Internet Access BBS: 510-704-1058/modem
- References: <Bz3s77.KrB@dei.unipd.it>
- Date: Sat, 12 Dec 1992 21:29:57 GMT
- Lines: 32
-
- POW2 (found on Goodies Disk #3) is nice and short.
- Here is my version which I call PWR2. It's longer (62.5 bytes vs. 48.5
- bytes for POW2), but it correctly handles negative powers (e.g., 2^-7)
- and can be generalized for any number base of interest. It's a bit
- faster, too.
-
- PWR2 ( number --> 0 or 1 )
- %%HP: T(3)A(D)F(.);
- \<< DUP LOG 2 LOG / IP DUP DUP SIGN + 2 SWAP ^ 2 ROT ^ 2 \->LIST
- SWAP POS SIGN
- \>>
-
- For a specified base use the following.
-
- PWRB ( number base --> 0 or 1 )
- %%HP: T(3)A(D)F(.);
- \<< \-> b
- \<< DUP LOG b LOG / IP DUP DUP SIGN + b SWAP ^ b ROT ^ 2 \->LIST
- SWAP POS SIGN
- \>>
- \>>
-
- Examples
- 4294967296 16 PWRB --> 1
- 983.4496 5.6 PWRB --> 1
-
- -- Brian Walsh
- brianw@holonet.net
-
- --
- -- Brian Walsh
- brianw@holonet.net
-