home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / hp48 / 6280 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.1 KB  |  43 lines

  1. Newsgroups: comp.sys.hp48
  2. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!agate!iat.holonet.net!brianw
  3. From: brianw@iat.holonet.net (Brian Walsh)
  4. Subject: Re: Power of 2
  5. Message-ID: <Bz611z.Dw6@iat.holonet.net>
  6. Organization: HoloNet National Internet Access BBS: 510-704-1058/modem
  7. References: <Bz3s77.KrB@dei.unipd.it>
  8. Date: Sat, 12 Dec 1992 21:29:57 GMT
  9. Lines: 32
  10.  
  11. POW2 (found on Goodies Disk #3) is nice and short.
  12. Here is my version which I call PWR2.  It's longer (62.5 bytes vs. 48.5
  13. bytes for POW2), but it correctly handles negative powers (e.g., 2^-7) 
  14. and can be generalized for any number base of interest.  It's a bit
  15. faster, too.
  16.  
  17. PWR2  ( number --> 0 or 1 )
  18. %%HP: T(3)A(D)F(.);
  19. \<< DUP LOG 2 LOG / IP DUP DUP SIGN + 2 SWAP ^ 2 ROT ^ 2 \->LIST 
  20. SWAP POS SIGN
  21. \>>
  22.  
  23. For a specified base use the following.
  24.  
  25. PWRB  ( number base --> 0 or 1 )
  26. %%HP: T(3)A(D)F(.);
  27. \<< \-> b
  28.   \<< DUP LOG b LOG / IP DUP DUP SIGN + b SWAP ^ b ROT ^ 2 \->LIST 
  29.   SWAP POS SIGN
  30.   \>>
  31. \>>
  32.  
  33. Examples
  34. 4294967296 16 PWRB --> 1
  35. 983.4496 5.6 PWRB --> 1
  36.  
  37. -- Brian Walsh
  38.    brianw@holonet.net
  39.  
  40. -- 
  41. -- Brian Walsh
  42.    brianw@holonet.net
  43.