Re: [xmoto-dev] svn 1404 : merged benetnash with trunk |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/xmoto-dev Archives
]
benenash :
To avoid this pb,
i wrote this in std::string App::formatTime(float fSecs)
/* hum, case, in which 0.9800 * 100.0 => 0.9799999*/
if(((int)(nHres * 100.0)) < ((int)((nHres * 100.0) + 0.001))) {
nH = ((int)((nHres * 100.0) + 0.001));
nH %= 100;
}
however, we should write funtions called :
float timetoFloatTime(int i_minutes, int i_seconds, int i_seconds);
void timeToIntTime(float i_time, int& o_minutes, int& o_seconds, int&
o_hundreaths);
which assumes :
i_minutes : i_seconds : i_seconds >= float
to FIX definitively this pb into 2 functions.
What do you think about this ?
Nicolas
Quoting Janek Polak <benetnash@xxxxxxxxxxxxxx>:
> Dnia Tue, 1 May 2007, Nicolas Adenis-Lamarre naskrobal
> > Janek Polak a écrit :
> > > Today morning I've invented that this floating point differences can be
> > > removed by changeing (replay_time < highscore_time) to (replay_time -
> > > highscore_time < -0.01). I'm not perfectly sure if it works, but this
> > > solution looks fine. I left comment in case someone invent something
> > > better.
> > i found a nice feature of sqlite,
> > it has not a lot of function, however, it allows to add news !
>
> > sqlite3_result_double(i_context, (double)((int)(v_value)));
>
> It is not working - it truncates 23.0 to 22.0 and so on - from numbers
> witout decimal digits it substracts 1. I think that issue may be caused
> by some floating point errors. Look at this:
>
> testowe$ cat x.cpp
> #include <iostream>
> using namespace std;
> main()
> {
>
> double x = 23.456;
> printf("%2.20f\n", x);
> printf("%2.20f\n", 100 * x);
> }
> testowe$ ./x
> 23.45599999999999951683
> 2345.59999999999990905053
>
>
> This 23.456 will be truncated by your function to 2345.5
> My nasty workaround is:
>
> sqlite3_result_double(i_context, (double)((int)(v_value + 0.0000001)));
>
> On the other hand we could round number with:
>
> sqlite3_result_double(i_context, floor(v_value + 0.5)));
>
> Anyway I've just commited first workaround and added xm_floor to both
> times:
>
> xm_floor(h.finishTime*100.0) > xm_floor(r.finishTime*100.0))
>
>
>