At Wed, Dec 26 2007 04:38:29 CET +0100, Michael Niedermayer wrote:
+#ifndef HAVE_ROUND +static av_always_inline double round(double x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUND */ iam ok with this, though if i were picky i could complain that your round implementation fails for 0.49999999999999994449 amongth others but i guess its good enough. Fixing that would make it slower and uglier with no real advantage ...
IIRC the glibc round has the same behavior inside the __DBL_EPSILON__ neighborhood of x.5. In addition you could complain that my fake round uses uncommon rounding mode. Michael
On Wed, Dec 26, 2007 at 08:29:14PM +0300, Michael Kostylev wrote:
At Wed, Dec 26 2007 04:38:29 CET +0100, Michael Niedermayer wrote:
+#ifndef HAVE_ROUND +static av_always_inline double round(double x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUND */ iam ok with this, though if i were picky i could complain that your round implementation fails for 0.49999999999999994449 amongth others but i guess its good enough. Fixing that would make it slower and uglier with no real advantage ...
IIRC the glibc round has the same behavior inside the __DBL_EPSILON__ neighborhood of x.5.
not here, just try: #define _ISOC99_SOURCE #include <math.h> #include <stdio.h> main(){ printf("%f %f\n", round(0.49999999999999994449), floor(0.49999999999999994449 + 0.5)); printf("%f %f\n", round(4503599627370497.0), floor(4503599627370497.0 + 0.5)); }
In addition you could complain that my fake round uses uncommon rounding mode.
not sure what you mean ... [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I count him braver who overcomes his desires than him who conquers his enemies for the hardest victory is over self. -- Aristotle
At Wed, 26 Dec 2007 19:12:16 +0100, Michael Niedermayer wrote:
+#ifndef HAVE_ROUND +static av_always_inline double round(double x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUND */ iam ok with this, though if i were picky i could complain that your round implementation fails for 0.49999999999999994449 amongth others but i guess its good enough. Fixing that would make it slower and uglier with no real advantage ... IIRC the glibc round has the same behavior inside the __DBL_EPSILON__ neighborhood of x.5. not here, just try: #define _ISOC99_SOURCE #include <math.h> #include <stdio.h> main(){ printf("%f %f\n", round(0.49999999999999994449), floor(0.49999999999999994449 + 0.5)); printf("%f %f\n", round(4503599627370497.0), floor(4503599627370497.0 + 0.5)); } In addition you could complain that my fake round uses uncommon rounding mode. not sure what you mean ...
Sorry, I skipped your "amongth others". Round() works exactly like it should. Michael
participants (2)
-
michaelni@gmx.at -
mik@niipt.ru