As most of you probably have already noticed, Binary Clock for Palm OS now supports the WristPDA. When creating the WristPDA frontend, I decided to add a cool new feature that shows the battery status permanentely(not only if low).
Recreating the Palm OS battery gadget is not too difficult, however, the program simply didn’t work. I managed to track the bug down to a line like this one:
srcrect.extent.x=0.3*percent;
A bit of research made me find out that most Palm OS compilers need globals to execute this operation – multiplication was no option, and division wasnt either. However, as you can see in the image below, the battery gadget works. But why?
![]()
I decided to substitute the multiplication with a lookup table. Here is the new code:
UInt8 coord[101]={0,0,0,0,1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,
6,7,7,7,8,8,8,9,9,9,9,10,10,10,11,11,11,12,12,12,12,13,13,13,
14,14,14,15,15,15,15,16,16,16,17,17,17,18,18,18,18,19,19,19,
20,20,20,21,21,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26
,26,26,27,27,27,27,28,28,28,29,29,29,30};
srcrect.extent.x=coord[percent];
Obviously, lookup tables don’t work for very big ranges of numbers – however, when you have less than a few hundred values, they make for a very good way around the problem.
Ever had such a problem?
Related posts:
Floating point multiplication and division need globals, I believe because they resolve into calls to the FloatMgr. But if you wrote something like
srcrect.extent.x=percent/3;
that should be just fine, since it’ll end up as integer division, which doesn’t need the FloatMgr…
Later,
Blake.
Why do you need float for such a task at all? Come on and think before posting…
Hi,
I used no float here…just a plain C multiplication….
Best regards
Tam Hanna
I’m not very familiar with C (Java fan), but 0.3 seems to be a float value, isn’t it? I think Blake Winton was right.
surly no need for floats as someone pointed out. also if you call float point manager directly using the sysTrap FlmEm, you need no globals. try it….