News for hackers. Stuff that matters.
Re:With Undefined Behavior, Anything Is Possible by jancsika on Sunday August 19, 2018 @10:52AM (#17794505)
The implementation for frexp uses type-punning.

Also, it adds a denormal and inf check which I don't need in this particular hot loop.

Re:With Undefined Behavior, Anything Is Possible by saagarjha on Sunday August 19, 2018 @06:39PM (#17796582)
Does it? On my computer it's a builtin (__builtin_frexp). But even if it did use type-punning, that doesn't make it legal for your program to do it. I don't believe there's any requirements on the C standard library to follow the standard themselves.

To answer the second part of your response, the correct way to do this yourself would be to memcpy the double and then inspect the result directly. Any compiler worth its salt will end up generating the assembly code you want (namely, no call to memcpy, just a couple of arithmetic shifts and masks).

Re:With Undefined Behavior, Anything Is Possible by jancsika on Monday August 20, 2018 @02:27PM (#17802471)
> To answer the second part of your response, the correct way to do this yourself would be to memcpy the double and then inspect the result directly. Any compiler worth its salt will end up generating the assembly code you want (namely, no call to memcpy, just a couple of arithmetic shifts and masks).

What does a compiler "worth its salt" do with the memcpy at "-O0"?

Re:With Undefined Behavior, Anything Is Possible by saagarjha on Monday August 20, 2018 @03:00PM (#17802808)