Skip to main content

Timeline for Floating Point XOR

Current License: CC BY-SA 4.0

25 events
when toggle format what by license comment
Sep 17, 2019 at 23:31 comment added Nick Kennedy @PeterCordes I think I’ve modified my answer in accordance with this - thanks!
Sep 17, 2019 at 23:30 history edited Nick Kennedy CC BY-SA 4.0
added 59 characters in body
Sep 17, 2019 at 21:11 comment added S.S. Anne I have a better solution (but it's C-only).
Sep 17, 2019 at 7:43 comment added Peter Cordes You don't need a comma or GNU C statement-expression here; the golf rules allow returning a value by modifying an input operand by reference. Also, since this is golf, this version doesn't strictly need the () safety parens. The "caller" just has to make sure not to use it as part of a larger expression. It already has lots of other weirdness (like taking args by reference and destroying one of them).
Sep 17, 2019 at 7:26 comment added Peter Cordes Note that this is only "safe" in debug mode, or if you use gcc -fno-strict-aliasing. Maybe you should have specified C++ (MSVC) if you wanted to use type punning via pointer casting. Although it does work on G++ with optimization disabled. BTW, this also requires a C++ implementation where sizeof(int) == sizeof(float), so it won't work on G++ for AVR or MSP430 for example. (TIO runs on x86, which uses 32-bit int and float like all "normal" modern CPUs).
Sep 16, 2019 at 18:36 comment added Nick Kennedy @PurpleP no because it takes pointers to floats as its arguments.
Sep 16, 2019 at 18:22 comment added Purple P Does this work on expressions like f(3.0+1.2,0)?
Sep 16, 2019 at 7:12 history edited Nick Kennedy CC BY-SA 4.0
added 33 characters in body
Sep 15, 2019 at 19:35 history edited Nick Kennedy CC BY-SA 4.0
added 17 characters in body
Sep 15, 2019 at 19:33 comment added Nishioka 37 bytes after merging with @AZTECCO's solution.
Sep 15, 2019 at 19:23 comment added AZTECCO Saves 2 more
Sep 15, 2019 at 19:11 comment added Nishioka Actually I've missed the obvious, so another -8 bytes: #define f(x,y)({*(int*)x^=*(int*)y;*x;})
Sep 15, 2019 at 19:03 history edited Nick Kennedy CC BY-SA 4.0
added 10 characters in body
Sep 15, 2019 at 19:00 comment added Nishioka Taking into consideration @Neil's suggestion it would get to 48 bytes: #define f(x,y)({*(int*)x^=*(int*)y;*(float*)x;})
Sep 15, 2019 at 18:54 comment added AZTECCO 62
Sep 15, 2019 at 18:47 comment added Neil Since you're using pointers, is it legal to use one of the inputs as the output? If so, you could write (*(int*)x^=*(int*)y).
Sep 15, 2019 at 18:41 history edited Nick Kennedy CC BY-SA 4.0
deleted 26 characters in body; deleted 3 characters in body
Sep 15, 2019 at 18:34 comment added Nishioka With gcc extensions, 54 bytes: #define f(x,y)({int z=*(int*)x^*(int*)y;*(float*)&z;})
Sep 15, 2019 at 18:33 comment added Nishioka Function-like macro, 63 bytes: #define f(x,y)[&]{int z=*(int*)x^*(int*)y;return*(float*)&z;}()
Sep 15, 2019 at 18:25 history edited Nick Kennedy CC BY-SA 4.0
added 54 characters in body
Sep 15, 2019 at 17:07 comment added Nishioka -2 bytes: using F=float;F f(F*x,F*y){int z=*(int*)x^*(int*)y;return*(F*)&z;}
Sep 15, 2019 at 17:00 history edited Nick Kennedy CC BY-SA 4.0
added 53 characters in body
Sep 15, 2019 at 16:46 comment added Arnauld You can save 4 more bytes with z=*(int*)x^*(int*)y;.
Sep 15, 2019 at 16:40 comment added 12Me21 You can remove the linebreaks to save 2 chars, and this also works in C
Sep 15, 2019 at 16:08 history answered Nick Kennedy CC BY-SA 4.0