Go Down

Topic: divmod10() : a fast replacement for /10 and %10 (unsigned) (Read 23 times) previous topic - next topic

robtillaart

#105
Oct 18, 2013, 08:17 pm Last Edit: Oct 18, 2013, 08:21 pm by robtillaart Reason: 1
Thanks Paul,

We can propose on the developers list that the divmod10 code (including #ifdef  to select asm or C version) becomes a separate .h file within the core.  I've seen " x/10 x%10" code constructs in several libs
(recently - http://forum.arduino.cc//index.php?topic=190472.0 - )

what do you think?

update: the divmod.h (?) could include work discussed here - http://forum.arduino.cc//index.php?topic=172635.0 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Paul Stoffregen

I think it's a good idea.

But I also find proposing stuff on the developer mail list to be exhausting.  I'm not personally planning to propose it and respond to the many "bike shedding" replies that are likely to result.

If you propose it, I'll chime in with a "+1".  When/if Arduino publishes it, I'll adopt whatever naming and header file convention they use.

Paul Stoffregen

If you do write up a good proposal on the developer mail list and Cristian replies favorably (really, anything other than saying no or probably not), perhaps I'll adopt it for Teensyduino 1.17 or 1.18?  I just posted the first release candidate today.  I don't have a deadline for 1.17, but unless there's any problems or other urgent stuff to add, I'll probably release sometime next week.

I can't see the harm in placing this into a header where it can be used by libraries.  There just needs to be some consensus from Arduino (where really, Cristian's voice is the only one that matters) so I don't end up publishing this in a way that will later break when/if they do it.

odometer

#108
Nov 03, 2013, 05:23 pm Last Edit: Nov 03, 2013, 05:25 pm by odometer Reason: 1
Personally, I would love to see it wrapped in a function which, for purposes of this post, I shall call digit().

Code: [Select]

Example use of digit():
long n = 4216738;
byte ones = digit(n, 0);  // now, ones == 8
byte tens = digit(n, 1);  // now, tens == 3
byte hund = digit(n, 2);  // now, hund == 7
byte thou = digit(n, 3);  // now, thou == 6
byte myri = digit(n, 4);  // now, myri == 1
byte lakh = digit(n, 5);  // now, lakh == 2
byte mill = digit(n, 6);  // now, mill == 4
byte cror = digit(n, 7);  // now, cror == 0

This would be extremely useful for displays.

I'm not sure how it should behave for negative numbers, though.

Tom Carpenter

for negatives you would have to first negate to make them positive, then use divmod10 then negate the resulting division value (the mod value I believe would stay positive). If you are doing it multiple times in a row then you would leave the results all positive and then at the very end negate the remaining division part.
~Tom~

robtillaart


Personally, I would love to see it wrapped in a function which, for purposes of this post, I shall call digit().

Code: [Select]

Example use of digit():
long n = 4216738;
byte ones = digit(n, 0);  // now, ones == 8
byte tens = digit(n, 1);  // now, tens == 3
byte hund = digit(n, 2);  // now, hund == 7
byte thou = digit(n, 3);  // now, thou == 6
byte myri = digit(n, 4);  // now, myri == 1
byte lakh = digit(n, 5);  // now, lakh == 2
byte mill = digit(n, 6);  // now, mill == 4
byte cror = digit(n, 7);  // now, cror == 0

This would be extremely useful for displays.

I'm not sure how it should behave for negative numbers, though.

@odometer
Have you seen this thread, - http://forum.arduino.cc/index.php?topic=179111.0 -
it uses divmod10 to increase the speed of the print class from which display classes are derived. But also the Serial class is derived from Print.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview