Pages: 1 ... 6 7 [8]   Go Down
Author Topic: divmod10() : a fast replacement for /10 and %10 (unsigned)  (Read 18153 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 -
« Last Edit: October 18, 2013, 01:21:15 pm by robtillaart » Logged

Rob Tillaart

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

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
« Last Edit: November 03, 2013, 11:25:23 am by odometer » Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

~Tom~

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

Rob Tillaart

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

Pages: 1 ... 6 7 [8]   Go Up
Jump to: