Possible issue and solution for RoundNanoFraction functions

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
MJFShark
Expert Boarder
Expert Boarder
Posts: 211
Joined: 04.06.2020, 13:59

Possible issue and solution for RoundNanoFraction functions

Post by MJFShark »

I ran into an issue with the rounding of nano timestamps a while ago. The suspect code is in ZSysUtils. My test case is:

x := RoundNanoFractionTo(123456789, 3);
and
x := RoundNanoFractionToMillis(123456789);

and I think x should be 123000000 but the actual result is 124000000.

This tracks back to:
const HalfFractModulos: array [TFractionRoundToScale] of Cardinal = ( 444444445, 44444445, 4444445, 444445, 44445, 4445, 445, 45, 5,0);
and to get it to give the results I'd expect I changed it to:
const HalfFractModulos: array [TFractionRoundToScale] of Cardinal = ( 500000000, 50000000, 5000000, 500000, 50000, 5000, 500, 50, 5,0);

Can someone check my logic here? Thanks!

-Mark
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Possible issue and solution for RoundNanoFraction functions

Post by marsupilami »

Hello Mark,

honestly I didn't check your loghic but I applied the patch ;)

Best regards,

Jan
Post Reply