New answers tagged

0

Lua, 73 bytes a,b=('II'):unpack(('ff'):pack(...))print((('f'):unpack(('I'):pack(a~b)))) Try it online! This code assumes 4-bytes unsigned integers and floats which is configuration on tio.run. Run as full program with input as arguments.


0

Ruby, 78 bytes There must be a shorter way to do this. ->x{[x.map{|v|[v].pack(?g).unpack(?N)[0]}.inject(&:^)].pack(?N).unpack(?g)[0]} Try it online! Input is an array of two floats.


2

ARM Thumb Machine Code, 6 bytes 80 EA 01 00 70 47 In assembly: EOR R0, R1 ; Exclusive Or of the first two params, store result in the return register BX LR ; Branch to the value stored in the Link Register (Return address) Under the standard Arm calling convention, the first two parameters are passed in the registers R0 and R1, results are returned ...


1

MATL, 10 bytes 4Z%Z}Z~9Z% Try it online! Splitting with Z} was shorter than taking two inputs ,4Z%]


2

VAX BASIC (later VMS BASIC, then Compaq Basic), 11 bytes H = F XOR G Seems a bit silly to me, obviously, older languages will do better because they didn't worry abut strong-typing issues as much.


1

Perl 5 -p, 31 27 bytes -4 bytes thanks to Grimy $\=unpack f,$a^=pack f,$_}{ Try it online!


1

Octave, 59 bytes @(a,b)(t=@typecast)(bitxor(t(a,u='int32'),t(b,u)),'single') Try it online! Typecast is the MATLAB/Octave way of casting without changing the underlying bits. This is required because bitxor only works on integers. No idea why they never implemented floating point numbers, even though you can explicitly specify the AssumedType as a third ...


1

Wolfram Mathematica, 50 bytes BitXor@@(FromDigits[RealDigits[#,2,32,0][[1]],2]&) Although I strongly suspect that this could be more golfed, the two extra arguments in RealDigits function seem to be necessary for getting a correct result. Try it online!


35

x86-64 machine code, 4 bytes 0f 57 c1 c3 In assembly: xorps xmm0, xmm1 ret This is a callable function that takes two floats or doubles as arguments (in xmm0 and xmm1) and returns a float or double (in xmm0). That matches the calling convention of both the WIN64 and SysV ABI, and works for floats as well as doubles.


3

Jelly + numpy, 89 83 bytes “(A“I^A“I)vF.item()”;"F“ṃ¹ʂ¥ƓİṀqȥF._hIµṙ⁷oĊEɱCKẒ7(¡£8þƙİ\lɓFɱy|Ɗð⁶S¦[Æ⁾»Ḳ¤¹ṣḢ}jʋƒŒV Try it online! Has the dubious honour of being longer than the Python 3 code it reproduces, largely because of the need to convert to/from numpy arrays and the fact that numpy isn’t loaded by Jelly so the __import__() built-in has to be used. A ...


2

Python 3 + numpy, 75 bytes from numpy import* f=lambda x,y:(x.view(int32)^y.view(int32)).view(float32) Try it online! Defines a lambda which takes two numpy float32 arrays as its arguments and returns a numpy float32 array.


2

C# (Visual C# Interactive Compiler), 92 bytes x=>BitConverter.Int32BitsToSingle(x.Aggregate(0,(a,b)=>a^BitConverter.SingleToInt32Bits(b))) Try it online!


8

C++ (gcc), 74 37 bytes #define f(x,y)(*(int*)x^=*(int*)y,*x) Try it online! I haven’t previously golfed in C++ so am grateful to all those who helped halve the size of the code! A macro which takes pointers to two floats as its arguments and returns a float. Thanks to @12Me1 for saving 2 bytes and @Arnauld for saving 4! Thanks to @Nishioka for saving ...


4

APL (Dyalog Unicode), 14 bytesSBCS Full program. Prompts for 1-column matrix of two IEEE 754 64-bit floating-point numbers (binary64) from stdin. Prints one such number to stdout. 645⎕DR≠⌿11⎕DR⎕ Try it online! ⎕ prompt (numbers that collapse to non-floats can be forced into floats with the function ⊃⊢⎕DR⍨645,⍨⎕DR) 11⎕DR convert to 1-bit Binary (1) Data ...


2

JavaScript (Node.js), 105 bytes Shorter Node version suggested by @Neil Takes input as (x)(y). x=>y=>(v=new Buffer(4),v.writeInt32LE((g=n=>v.writeFloatLE(n)&&v.readInt32LE())(x)^g(y)),v.readFloatLE()) Try it online! JavaScript (ES6), 115 bytes Takes input as an array of 2 floats. a=>(v=new DataView(new ArrayBuffer(4))).getFloat32(v....


Top 50 recent answers are included