On Sat, Aug 28 17:43, Kevin Wolf wrote: > + libm: fmod implementiert > > Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx> > --- > src/modules/include/math.h | 4 ++ > src/modules/lib/stdlibc/math/fmod.c | 69 +++++++++++++++++++++++++++++++++++ > 2 files changed, 73 insertions(+), 0 deletions(-) > create mode 100644 src/modules/lib/stdlibc/math/fmod.c > > diff --git a/src/modules/include/math.h b/src/modules/include/math.h > index 207fd3d..968411b 100644 > --- a/src/modules/include/math.h > +++ b/src/modules/include/math.h > @@ -117,6 +117,10 @@ long double nearbyintl(long double x); > double rint(double x); > double pow(double x, double y); > > +double fmod(double x, double y); > +float fmodf(float x, float y); > +long double fmodl(long double x, long double y); > + > #ifdef __cplusplus > }; // extern "C" > #endif > diff --git a/src/modules/lib/stdlibc/math/fmod.c b/src/modules/lib/stdlibc/math/fmod.c > new file mode 100644 > index 0000000..d691ca1 > --- /dev/null > +++ b/src/modules/lib/stdlibc/math/fmod.c > @@ -0,0 +1,69 @@ > +/* > + * Copyright (c) 2010 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include <math.h> > +#include <errno.h> > + > +double fmod(double x, double y) > +{ > + double res; > + > + if (y == 0.0) { > + errno = EDOM; > + return NAN; > + } > + > + asm("fprem" : "=t" (res) : "0" (x), "u" (y)); > + return res; > +} > + > +float fmodf(float x, float y) > +{ > + float res; > + > + if (y == 0.0) { > + errno = EDOM; > + return NAN; > + } > + > + asm("fprem" : "=t" (res) : "0" (x), "u" (y)); > + return res; > +} > + > +long double fmodl(long double x, long double y) > +{ > + long double res; > + > + if (y == 0.0) { > + errno = EDOM; > + return NAN; > + } > + > + asm("fprem" : "=t" (res) : "0" (x), "u" (y)); > + return res; > +} Hm wenn das da mit dem == 0.0 passt kann das rein. Müsste da nicht -0.0 auch noch abgefangen werden? Acked-by: Antoine Kaufmann <toni@xxxxxxxxxx> -- Antoine Kaufmann <toni@xxxxxxxxxxxxxxxx>
Attachment:
pgpIRgskWhTiK.pgp
Description: PGP signature