Bits of integer

12152022, 07:44 PM
(This post was last modified: 08202023 05:13 PM by Albert Chan.)
Post: #41




RE: Bits of integer
(12152022 04:08 PM)Thomas Klemm Wrote: Can we expect your explanations in APL instead of Lua from now on? Lua is still my favorite. I don't like writeonce language, with comments that is much longer than code. Any editing of code, you then have to correct for old comments. The Law of Leaky Abstractions  Joel on Software Quote:All nontrivial abstractions, to some degree, are leaky. Devlin's Angle, Base Consideration, Feb 1996 Quote:Playing with arithmetic having negative bases is an amusing classroom exercise, but, strange as it may seem, a computer was once built that used "2" base arithmetic. It was the UMC1, a Polishmade computer of the late 1950s and early 1960s, of which several dozen were made and installed. base ← ⊥⍣¯1 ¯2 base 123 DOMAIN ERROR APL code cannot convert to base 2. It may take lots of work to fix. Same problem solved in Lua is easy. Code: function base(n, b) lua> require'pprint' lua> pprint(base(123, 2))  9 bits { 1, 1, 0, 0, 0, 1, 1, 1, 1 } lua> pprint(base(123, 2))  7 bits { 1, 1, 1, 1, 0, 1, 1 } For base 2, we can directly lookup binary exponent. lua> logb(123) + 1  bits of 123 7 Update: base(n, b) extended to negative n's. It uses Lua floormod property. (sign matching divisor) With this update, we have invariant: horner(base(n, b), b) = n lua> pprint(base(123, 2))  negative b, always nonnegative digits { 1, 0, 0, 0, 0, 1, 0, 1 } lua> pprint(base(123, +2))  positive b, sign of digits = sign of n { 1, 1, 1, 1, 0, 1, 1 } 

12172022, 02:31 AM
Post: #42




RE: Bits of integer
(12132022 02:37 AM)Joe Horn Wrote: Here's a bruteforce implementation of that method: That's not that much for a calculator that came out 40 years ago. My Sanyo (1977) needs more than 30s to compute the factorial of 69!! I should have bought one 16C when you could find it in stores… Of course, with a DM16L, it would be faster (and it's about half the price). (12132022 09:17 AM)Joe Horn Wrote: Here's a 16Conly routine that doesn't require any looping. The LJ command is on the [g] [A] key. #B is on the [g] [7] key. I have tried both of your programs at: https://stendec.io/ctb/rpn_prog.html Thank you! Too bad the RPL calculators don't have all the functions of the 16C. However, trying to program the missing functions might be a good exercise! Bruno Sanyo CZ0124 ⋅ TI57 ⋅ HP15C ⋅ Canon X07 + XP140 Monitor Card ⋅ HP41CX ⋅ HP28S ⋅ HP50G ⋅ HP50G 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)