{"id":57376,"date":"2026-11-25T19:44:16","date_gmt":"2026-11-25T18:44:16","guid":{"rendered":"https:\/\/hooxies.nl\/?page_id=57376"},"modified":"2026-11-25T21:08:07","modified_gmt":"2026-11-25T20:08:07","slug":"pimpimp","status":"publish","type":"page","link":"https:\/\/hooxies.nl\/?page_id=57376","title":{"rendered":"PIM+PIMP"},"content":{"rendered":"<p><b>Display<\/b><br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-hp41cx.jpg\"><img decoding=\"async\" style=\"cursor:pointer; cursor:hand;width: 226px; height: 104px;\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-hp41cx.jpg\" border=\"0\" \/><\/a> <a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-dm41x.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-dm41x.jpg\" alt=\"\" width=\"173\" height=\"104\"\/><\/a> <br \/>\n<em>(HP-41CX, Hewlett Packard 1983 and DM41X, <a href=\"https:\/\/www.swissmicros.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">SwissMicros<\/a> 2020)<\/em><br \/>\n&nbsp;<\/p>\n<p><b>Overview<\/b><br \/>\nTwo programs calculate &pi; (pi) to N decimals with the formula of John Machin (1706): <tt>PIM<\/tt> and <tt>PIMP<\/tt>. <tt>PIM<\/tt> stores 5 decimals in every data register (base 100&nbsp;000). <tt>PIMP<\/tt> is the packed version: it stores 10 decimals (two groups of 5) in every register, so about twice as many decimals fit in the same memory. Both programs set the SIZE themselves, show the maximum number of decimals when the memory is too small, measure the calculation time with the stopwatch and show &pi; 10 decimals per line. The formulas used are:<br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;&pi; = 16&middot;atan(1\/5) &minus; 4&middot;atan(1\/239)<\/tt><br \/>\n<tt>&nbsp;&nbsp;&nbsp;&nbsp;atan(1\/x) = 1\/x &minus; 1\/3x<sup>3<\/sup> + 1\/5x<sup>5<\/sup> &minus; 1\/7x<sup>7<\/sup> + &hellip;<\/tt><\/p>\n<p>The series for 1\/5 and 1\/239 are added term by term until the term becomes zero. Both programs use the built-in X-Functions (PSIZE, SIZE?, ALENG) and Time functions (SETSW, RUNSW, STOPSW, RCLSW, ATIME24) of the HP-41CX and DM41X. More about the method: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Machin-like_formula\" rel=\"noopener noreferrer\" target=\"_blank\">Machin-like formula<\/a> (Wikipedia), <a href=\"https:\/\/mathworld.wolfram.com\/MachinsFormula.html\" rel=\"noopener noreferrer\" target=\"_blank\">Machin&rsquo;s Formula<\/a> (Wolfram MathWorld) and <a href=\"https:\/\/en.wikipedia.org\/wiki\/John_Machin\" rel=\"noopener noreferrer\" target=\"_blank\">John Machin<\/a> (Wikipedia).<br \/>\n&nbsp;<\/p>\n<p><b>Description<\/b><br \/>\n<tt>PIM<\/tt> keeps two multi-precision numbers in the data registers: T, the current term of the series, and S, the sum that becomes &pi;. Each number takes n = INT(N\/5)+3 registers of 5 decimals (SIZE = 2n+12); the first register holds the integer part and the last registers are guard digits, so N is rounded down to a multiple of 5. Subroutine LBL 01 adds &plusmn;T&middot;atan(1\/x) to S: T starts with the coefficient (16 or 4) and is divided by x (5 or 239), from then on by x<sup>2<\/sup> for every term. Each term is also divided by 2k+1 and added to or subtracted from S, register by register, with the remainder carried to the next register. Registers of T that have become zero are skipped, so every term is faster than the previous one, and the series stops when T is zero. Finally the carries in S are normalised from right to left (MOD 100&nbsp;000), the time is shown and &pi; is displayed in groups of 5 with leading zeros.<br \/>\n&nbsp;<br \/>\n<tt>PIMP<\/tt> works the same way, but packs two groups of 5 decimals into one register (R = hi&middot;100&nbsp;000 + lo). It needs n = INT((N+9)\/10)+2 registers per number (SIZE = 2n+18), and N is rounded up to a multiple of 10. Every register is unpacked, divided group by group and packed again, so all intermediate values stay below 10<sup>10<\/sup> and remain exact. S is kept in a &ldquo;balanced&rdquo; form (the high group may be negative) and a small carry goes to the register on the left; at the end one pass from right to left (MOD 10<sup>10<\/sup>) turns S into normal digits. The program is longer than <tt>PIM<\/tt>, but the number of decimals that fits in memory is almost doubled.<br \/>\n&nbsp;<\/p>\n<p><b>Metrics<\/b><br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-metrics.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-metrics.jpg\" alt=\"\" width=\"413\" height=\"112\" \/><\/a><br \/>\nAll V41 times were measured with V41 at top speed and maximum turbo: <tt>PIM<\/tt> with 20 and 600 decimals and <tt>PIMP<\/tt> with 20 decimals. The other times (&asymp;) are estimates: the run time grows with N<sup>2<\/sup>, and <tt>PIMP<\/tt> needs about 1.8 times as many program steps per decimal as <tt>PIM<\/tt>. The V41 at maximum turbo runs about 200 program steps per second and a real HP-41CX about 8, so the HP-41CX times are estimated as 25 times the V41 times. The DM41X has the same memory as the HP-41CX, so the maximum number of decimals is the same; it runs faster than the HP-41CX, but its times have not been measured yet.<br \/>\n&nbsp;<\/p>\n<p><b>Example (1)<\/b><br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-examples.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-examples.jpg\" alt=\"\" width=\"413\" height=\"284\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Example (2)<\/b><br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-examples.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-examples-413x285.jpg\" alt=\"\" width=\"413\" height=\"285\" class=\"alignnone size-medium wp-image-57421\" srcset=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-examples-413x285.jpg 413w, https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-examples-989x682.jpg 989w, https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-examples-768x530.jpg 768w, https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-examples.jpg 1099w\" sizes=\"auto, (max-width: 413px) 100vw, 413px\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Program Listing (PIM)<\/b><br \/>\nThe listing of <tt>PIM<\/tt> is given below. The decimals are calculated first; the time is measured with the stopwatch. Only the global label <tt>PIM<\/tt> is used.<br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-program-6a.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-program-6a.jpg\" alt=\"\" width=\"413\" height=\"342\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Program Listing (PIMP)<\/b><br \/>\nThe listing of <tt>PIMP<\/tt> is given below. The decimals are calculated first; the time is measured with the stopwatch. Only the global label <tt>PIMP<\/tt> is used.<br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-program-8.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-program-8.jpg\" alt=\"\" width=\"413\" height=\"261\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Registers, Labels and Flags (PIM)<\/b><br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-registers.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim-registers.jpg\" alt=\"\" width=\"413\" height=\"269\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Registers, Labels and Flags (PIMP)<\/b><br \/>\n<a rel=\"hp-41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-registers.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pimp-registers.jpg\" alt=\"\" width=\"413\" height=\"348\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p><b>Downloads<\/b><br \/>\nPDF format of programs <a rel=\"41cx_pim\" href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim.pdf\">PIM+PIMP<\/a>.<br \/>\nRAW\/TXT format of programs <a href=\"https:\/\/hooxies.nl\/wp-content\/uploads\/2026\/11\/pim.zip\">PIM+PIMP<\/a> (in zip file).<br \/>\n&nbsp;<\/p>\n<div style=\"font-size: 12px;\">This program is copyright and is supplied without representation or warranty of any kind. The author assumes no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof<\/div>\n<p><i>&copy; 2006-2026 by Auke Hoekstra<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display (HP-41CX, Hewlett Packard 1983 and DM41X, SwissMicros 2020) &nbsp; Overview Two programs calculate &pi; (pi) to N decimals with the formula of John Machin (1706): PIM and PIMP. PIM stores 5 decimals in every data register (base 100&nbsp;000). PIMP is the packed version: it stores 10 decimals (two groups of 5) in every register, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-57376","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/57376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=57376"}],"version-history":[{"count":14,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/57376\/revisions"}],"predecessor-version":[{"id":57422,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/57376\/revisions\/57422"}],"up":[{"embeddable":true,"href":"https:\/\/hooxies.nl\/index.php?rest_route=\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/hooxies.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}