Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #91405
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: How can I get an implementation of fmod()? |
| Date | 2023-08-25 09:19 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <uc9km9$3ttlb$1@dont-email.me> (permalink) |
| References | <b1f2568f-0221-4b79-b6c6-115abd875541n@googlegroups.com> |
Am 25.08.2023 um 08:25 schrieb Megumin: > How does remainder() in cmath works and is there any simple but fairly precise fmod that can be implemented without using double or long double? > I'm currently trying to implement fmodf(float x,float y) myself in assembly, and seems like in IEEE754, if I try to do as follows, the precision will f-up badly if x>>y in fact if x/y is more than 2^23 this will just makes no sense at all. > r1 = f32(x); > r2 = f32(y); > r3 = div_f32(r1,r2); //precision:2ulp > r4 = trunc(r3)// this is where things go bad if r3 is more than 2^23 it does nothing and I will get no remainder. > r4 = multi_f32(r4,r2); > r4 = subtract_f32(r1,r4); > result = r4; > Look at the /sysdeps/ieee754/dbl-64/e_fmod.c glibc code. They've changed the code for the 8/1/2023 release and made the algorithm multiple times faster. The fmod() result has no precision loss. Don't bother with x87's FPREM. It's claimed to be excact but actally its an approximation on the CPU's I've recently checked (Zen1, Zen2, Zen4, Skylake).
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How can I get an implementation of fmod()? Megumin <chrisramirez0227@gmail.com> - 2023-08-24 23:25 -0700
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-25 09:19 +0200
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-25 09:35 +0200
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-25 09:49 +0200
Re: How can I get an implementation of fmod()? James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-08-25 04:34 -0400
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-25 10:37 +0200
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-25 10:43 +0200
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-25 11:20 +0200
Re: How can I get an implementation of fmod()? Megumin <chrisramirez0227@gmail.com> - 2023-08-30 22:52 -0700
Re: How can I get an implementation of fmod()? Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-31 11:00 +0200
Re: How can I get an implementation of fmod()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-31 21:48 +0100
Re: How can I get an implementation of fmod()? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-31 14:37 -0700
Re: How can I get an implementation of fmod()? James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-08-25 04:44 -0400
csiph-web