This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Don't call double rint from float powf.


On 12/12/2017 01:00 PM, Jim Wilson wrote:
On 12/11/2017 04:37 PM, Craig Howland wrote:
On 12/11/2017 07:08 PM, Jim Wilson wrote:
- if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL;
+               if(x<0.0&&rintf(y)!=y) exc.retval = -HUGE_VAL;
              }
              if (_LIB_VERSION == _POSIX_)
                  errno = ERANGE;
To be most rigorous, "0.0" on the same lines as the rintf() should be "0.0F" (as otherwise the comparison strictly should be done in double).  (Not addressing the exact change you are making, but is the same class of fix and are on the same line of source code.)

Any reasonable compiler will get this right.  GCC does a float compare here even if you compile without optimization.  So no fix here is required, though I can redo the patch if you want.

If you don't mind, it would be best that way, as it keeps the source compliant with the C standard in terms of requiring a float comparison.  But it also could be cleaned up later on, as I expect that there are some others that are the same way that could also use it.

(It is an interesting thing to consider to decide if GCC is doing the right thing here, or not.  While it knows that it is comparing against 0 and that converting it from double 0 to float 0 has no runtime side effects, the user could have purposely done it this way because they wanted to avoid a float comparison.  I do agree that making it a float comparison is a good choice, just that it could potentially be considered to be not in compliance with the standard.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]