--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/87b7dbad-2d98-4e1a-899e-4e5342691465%40isocpp.org.
constexpr float f = 13.f % 2.1f; // f == 0.4
constexpr float f = std::fmod(13.f, 2.1f); // not compilable
On Tue, Apr 24, 2018 at 10:07 AM, <ryan...@digipen.edu> wrote:
I think that it is discriminatory that integers have modulus operators but floats do not.It is unacceptable, and that is my opinion.I propose we add the modulus operator to floating point types.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/87b7dbad-2d98-4e1a-899e-4e5342691465%40isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/90618fc9-0eb2-42bd-ad8e-3c983a3fde77%40isocpp.org.
From: ryan...@digipen.edu Sent: Tuesday, April 24, 2018 3:47 AM To: ISO C++ Standard - Future Proposals Reply To: std-pr...@isocpp.org Subject: Re: [std-proposals] Add the modulus operator to floating point types. |
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20180424102929.5099602.62637.51047%40gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/90618fc9-0eb2-42bd-ad8e-3c983a3fde77%40isocpp.org.
I presume that f is floating-point, and mod is modulo, in std::fmod.In which case, fmod is a "function that does modulo on 2 floating-point arguments".I propose for a floating-point modulus operator as it's behavior has already been defined in fmod as such.Why is there a "function that does modulo on 2 floating-point arguments" but no "operator that does modulo on 2 floating-point operands"?
What's more? Other languages (like c#) have their own % float operator, having the exact same behavior as fmod from what I've read: "The returned value has the same sign as the numerator and is less than denominator in magnitude". I had to highlight the word exact because it is not surprising.
Sorry for the deleted posts.I was not thinking clearly.On Tuesday, April 24, 2018 at 3:07:12 PM UTC+8, ryan...@digipen.edu wrote:I think that it is discriminatory that integers have modulus operators but floats do not.It is unacceptable, and that is my opinion.I propose we add the modulus operator to floating point types.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7db24788-d433-4c19-839b-c1e9b2d2a98c%40isocpp.org.
constexpr float f = 13.f % 2.1f; // f == 0.4
constexpr float f = std::fmod(13.f, 2.1f); // not compilable
The remainder can be thought of as the value that is lost as a result of rounding down of the quotient. The rounding occurs because integers have a fixed resolution of 1. Floats do not.For integer division, if n/d=q and n%d=r then if follows that q*d+r=n. So having a remainder of 0.4f in your example only makes sense if 13.f / 2.1f == 6 and that would change the behavior of floating-point division.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a2825d04-5d39-4ce1-bcf3-f20db6fcd430%40isocpp.org.
The modulo operation clearly has only one intuitive behaviour
On Wed, Apr 25, 2018 at 12:31 PM, Jakob Riedle <jakob....@gmail.com> wrote:The modulo operation clearly has only one intuitive behaviour
As I said before, if floating-point % existed, then 13.0f % 2.6f would result in
0.40000057220458984375f exactly. The values written as 0.40000056f,
0.40000057f, and 0.40000058f all convert to that value, but the value written
as 0.4f does not, being exactly equal to 0.4000000059604644775390625f.
This is not at all intuitive
It is intuitive to anyone who understands floating point arithmetic.
The same thing appears in a large number of common float operations -
I don't see how this is directly related to the post.
I'm also in favour of the change. We can talk about the uses of it and the pitfalls of floating representation until the cows come home, but that doesnt change that there are uses (justifying the existence of fmodf in the first place), that it is already deemed useful enough to be effortlessly implemented in a variety of other languages, and that the "different code for different types" ethos is not the C++ way.Whether or not I believe that the change is feasible is another matter. I can only see three reasonable approaches. The first is to get the C community on board. Failing that, we could figure out a way of allowing operator functions on primitives without demolishing the language. Failing that, we could standardise a wrapping class around certain primitives that allows us to embellish them without the negotiations required for the previous two approaches.These are in descending order of usefulness but ascending order of ease.
It is intuitive to anyone who understands floating point arithmetic.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdZJ8Rcn%2B6Pto2%2B%2B6RLOaYwWCBV8zcoUJYciYnCsO-1Avg%40mail.gmail.com.
It would help if we had a concrete example to test with. With infinite
precision, 13.0 % 2.6 should be zero, not 0.4.
Am Dienstag, 24. April 2018 11:43:44 UTC+2 schrieb John McFarlane:The remainder can be thought of as the value that is lost as a result of rounding down of the quotient. The rounding occurs because integers have a fixed resolution of 1. Floats do not.For integer division, if n/d=q and n%d=r then if follows that q*d+r=n. So having a remainder of 0.4f in your example only makes sense if 13.f / 2.1f == 6 and that would change the behavior of floating-point division.
The modulo operation clearly has only one intuitive behaviour (excluded signed operands) which additionally has a significant amount of users that would benefit from such a change, regardles of whether the committee prioritises that way.
I am in favor of this change. +1Jakob
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a2825d04-5d39-4ce1-bcf3-f20db6fcd430%40isocpp.org.
Then you would not like fixed-point modulo behavior which uses integer arithmetic but at scales which are powers of two.
On Wed, Apr 25, 2018 at 8:55 PM John McFarlane <jo...@mcfarlane.name> wrote:Then you would not like fixed-point modulo behavior which uses integer arithmetic but at scales which are powers of two.
Your funny numbers have an operator% defined, though, so maybe you're supporting the OP :-)
The basic problem is that a%b ≝ a-b×⌊a÷b⌋, and the division will not give people theresult they expect from examining the numbers they have written in the code, or otherwise
converted from decimal to binary, because those numbers are usually a tiny bit larger or a
tiny bit smaller than their decimal forms. A lot of people don't understand this, and I would
guess that proportion is particularly high among those who are asking for a float operator%.
If they knew what it would do, they wouldn't want it, because it doesn't do what they want.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdYBu%2BxQj3yuQd%2B88xT1Ea7pnibVDP6_dHgvAmyK-Z4d_g%40mail.gmail.com.
Would you be equally happy if fmod was made constexpr?(instead of % for floats)
Did you spend any time researching this topic before you posted? The issue with your example isn't fmod but constexpr in <cmath> and the proposal to support this is linked from the top google search hit for "constexpr c++ cmath".https://stackoverflow.com/questions/42189190/why-doesnt-the-c-standard-library-provide-constexpr-versions-of-the-cmath-fun points to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0533r0.pdf, which containsconstexpr float fmod(float x, float y); // see [library.c]constexpr double fmod(double x, double y);constexpr long double fmod(long double x, long double y); // see [library.c]constexpr float fmodf(float x, float y);constexpr long double fmodl(long double x, long double y);