Quantcast
Channel: Cemetech
Viewing all articles
Browse latest Browse all 75345

Casio Prizm/FX Development & Programming :: RE: Math with doubles gives wrong results

$
0
0
Author: gbl08ma
Posted: 14 Mar 2013 12:17:06 pm (GMT -5)

I just found out that if I set the values in code, like this:

Code:
ihour = 1; iminute = 20; isecond = 30;
fhour = ihour; fminute = iminute; fsecond = isecond; fmillisecond = imillisecond;
hourfraction = fhour+fminute/60.0+fsecond/(60.0*60.0);

...the result is the adequate hour fraction. However, if I use RTC_GetTime to set the values of the unsigned ints...

Code:
RTC_GetTime( &ihour, &iminute, &isecond, &imillisecond );
fhour = ihour; fminute = iminute; fsecond = isecond; fmillisecond = imillisecond;
hourfraction = fhour+fminute/60.0+fsecond/(60.0*60.0);

...it will give wrong results.
Now I really don't know what to do... it's not the floating point that is wrong anymore, but this is even stranger.

I also noted that the drift between the correct result and the result it returns gets higher as it gets later into the day. For example, at 00:06:21, it calculates the fraction that corresponds to 00:06:33; but at 16:08:18, it calculates the fraction that corresponds to 22:08:24.
I'll try not using RTC_GetTime but rather accessing the RTC registers and see what gives.
_________________
My blog, where I write about random things... | tiny URL shortener
View JPEG images on your Prizm | Utilities for the Casio Prizm - clock, stopwatch, calendar/agenda, add-in manager and more!


Viewing all articles
Browse latest Browse all 75345

Trending Articles