Truncating to Integer & Fraction--HP-35A/21A « Next Oldest | Next Newest »

 ▼ Matt Agajanian Unregistered Posts: 980 Threads: 239 Joined: Aug 2006 03-29-2012, 11:01 AM Hello all. Fantastic job on the D.MS<-->D.DDD conversion routines. I tried developing some algorithms last night. In comparison, yours were quite streamlined. Another pair of techniques I've been considering: How do I extract the fractional and integer parts of values. I tried using logs, adding/subtracting 1/2 to round the decimal portion out, etc. and a memory location with some arithmetic manipulation but my methods are pretty cumbersome. Just as well, I've also been trying to create routines to truncate to n decimal places. My ideas were to add some power of 10 to the number and then subtract it down to the original number with the desired decimal. But, the internal rounding of the 35 would round my values up if the n+1th digit was >=5. Any thoughts? Edited: 29 Mar 2012, 7:12 p.m. after one or more responses were posted ▼ Luiz C. Vieira (Brazil) Unregistered Posts: 591 Threads: 16 Joined: Feb 2012 03-29-2012, 01:33 PM HI. Some calculators have these 'functions' already implemented INT, IP - returns the integer portion of a number (*) FRAC, FP - returns fractional part of a number (*) The HP12C has INTGR, intended to make no confusion with INT, which refers to interest rate in financial calculators. I am curious: which calculator you are willing to implement? Or is it just a matter of developing the algorithm yourself? I am asking these questions because I sometimes challenge myself by writing routines and algorithms to compute some calculations already implemented. Lately I am trying to implement integer, binary multiplication in microcontrollers with the fewest steps possible. Cheers. Luiz (Brazil) Edited: 29 Mar 2012, 1:34 p.m. ▼ Matt Agajanian Unregistered Posts: 980 Threads: 239 Joined: Aug 2006 03-29-2012, 07:10 PM Hello there. As the message title indicates, I'm looking for an integer and fractional truncation routines for the 1972 HP-35 and its successor the HP-21. Edited: 29 Mar 2012, 7:11 p.m. ▼ Eric Smith Unregistered Posts: 2,309 Threads: 116 Joined: Jun 2005 03-29-2012, 08:09 PM As you may have figured out, there are actually reasons why some people bought midrange or high-end calculators, rather than the bottom of the line. Luiz C. Vieira (Brazil) Unregistered Posts: 591 Threads: 16 Joined: Feb 2012 03-29-2012, 10:44 PM HI. I failed to understand HP-35A/21A as both the HP35 and HP21, I actually did not figure that out. In this case I second the other guys: I'd store the value in one available register (the HP21 has only one memory register out of the memory stack, IIRC) and key in the integer or factional part whenever needed. I'd guess that such resource in a non-programmable, ROM-limited calculator might not have been taken as essential, though. Cheers. Luiz (Brazil) Gerson W. Barbosa Unregistered Posts: 2,761 Threads: 100 Joined: Jul 2005 03-29-2012, 07:44 PM Hello Luiz, Quote: Lately I am trying to implement integer, binary multiplication in microcontrollers with the fewest steps possible. On the Z80, I used to do the following. Not the fewest number of bytes, I fear: ``` org \$c000 ld hl,0 ld c,\$ff ld de,\$ff loop: ld a,c cp 0 ret z and 1 jr z,loop0 add hl,de loop0: srl c sla e rl d jr loop``` Cheers, Gerson. ▼ Luiz C. Vieira (Brazil) Unregistered Posts: 591 Threads: 16 Joined: Feb 2012 03-29-2012, 10:40 PM HI, Gerson. Thank you, very interesting. ``` org \$c000 ld hl,0 ld c,\$ff ld de,\$ff loop: ld a,c cp 0 ret z and 1 jr z,loop0 The key for the process... add hl,de ... and the resulting product is in hl, right? loop0: srl c sla e rl d jr loop```I'll try to port it to the ATMEL structure, I think it is not going to be that hard. Thanks a lot! Cheers. ▼ Gerson W. Barbosa Unregistered Posts: 2,761 Threads: 100 Joined: Jul 2005 03-29-2012, 10:58 PM Hi Luiz, It's based on Russian peasant multiplication. It looks like their peasants are more creative than ours. Remember this Semp Toshiba ad? :-) Cheers, Gerson. ▼ Matt Agajanian Unregistered Posts: 980 Threads: 239 Joined: Aug 2006 03-31-2012, 10:45 PM You know, that Russian Peasant Multiplication trick is pretty cool! They say you learn something new everyday. Well, this is the coolest one yet! Andrés C. Rodríguez (Argentina) Unregistered Posts: 1,193 Threads: 43 Joined: Jul 2005 03-29-2012, 02:58 PM IMHO, for that machine class, manual truncation is the way. ▼ Gerson W. Barbosa Unregistered Posts: 2,761 Threads: 100 Joined: Jul 2005 03-29-2012, 05:19 PM Ditto! Matt Agajanian Unregistered Posts: 980 Threads: 239 Joined: Aug 2006 03-31-2012, 10:36 PM You've got a point there. But, even so, it was a challenging exercise in developing a unique algorithm.

 Possibly Related Threads… Thread Author Replies Views Last Post HP Prime program: rounding to a fraction Patrice 3 1,668 10-31-2013, 06:16 AM Last Post: Joe Horn HP Prime: Edit integer in RPN mode plivesey 15 4,827 10-18-2013, 04:34 PM Last Post: kris223 HP15c continued fraction for Ln(Gamma) Tom Grydeland 0 1,088 09-30-2013, 05:48 AM Last Post: Tom Grydeland Prime Edit Integer kris223 8 2,514 09-24-2013, 06:43 PM Last Post: kris223 Understanding HP-16C integer division Jimi 18 5,058 10-16-2012, 09:13 PM Last Post: Eddie W. Shore HP-35A Production Run Questions Matt Agajanian 0 900 07-02-2012, 09:02 PM Last Post: Matt Agajanian HP-35A/21 D.MS<-->Decimal degrees routines Matt Agajanian 9 2,840 03-29-2012, 11:03 AM Last Post: Matt Agajanian WP34S x=? in integer mode Harald 8 2,169 03-13-2012, 07:00 PM Last Post: Paul Dale Wp34s beta 2: possible serious bug in integer mode Cristian Arezzini 3 1,242 06-10-2011, 06:01 PM Last Post: Cristian Arezzini wp34s Integer Word Size versus 16C Jake Schwartz 7 2,156 05-06-2011, 02:19 AM Last Post: Walter B

Forum Jump: