Skip to main content
Share Your Experience: Take the 2024 Developer Survey
57 votes

Floating Point XOR

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 ...
user555045's user avatar
  • 1,419
35 votes

Float 754 to Hamming

x86_64 machine language (Linux), 16 bytes ...
ceilingcat's user avatar
  • 7,605
30 votes

Implement Ash's float division

Haskell, 35 bytes x?y|isNaN$x/y=tanh x*tanh y|0<1=x/y Try it online! The relevant function is (?), which takes two ...
Delfad0r's user avatar
  • 6,266
18 votes

Convert an integer to IEEE 754 float

Python, 55 bytes Correct as per original challenge description (always add 2^23 to mantissa) but not per IEEE. ...
loopy walt's user avatar
  • 16.7k
18 votes

Vanilla Natural Logarithm Challenge

Excel, 19 16 bytes With many thanks to Dominic van Essen for the 3-byte save: =1E9*(A1^1E-9-1) Previous: =9^9*(A1^(1/9^9)-1) ...
Jos Woolley's user avatar
  • 1,942
17 votes

Convert an integer to IEEE 754 float

x86 32-bit machine code, 5 bytes D9 44 24 04 C3 Try it online! Following the cdecl calling convention, this takes the 32-bit ...
m90's user avatar
  • 10.5k
14 votes

Convert an integer to IEEE 754 float

Rust, 14 bytes f32::from_bits Not even reached the 30 byte min limit for posts
mousetail's user avatar
  • 12.6k
13 votes

Implement Ash's float division

JavaScript (ES6), 45 bytes Expects (a)(b), as Numbers. Returns a Number. ...
Arnauld's user avatar
  • 193k
12 votes

Float 754 to Hamming

C (gcc), 82 68 bytes 9 bytes thanks to Neil. evil floating point bit level hacking s;f(long n){double d=n;n=*(long*)&d;for(s=0;n;n*=2)s+=n<0;return s;} ...
Leaky Nun's user avatar
  • 49.8k
12 votes

Floating Point XOR

C++ (gcc), 74 32 bytes #define f(x,y)*(int*)x^=*(int*)y Try it online! I haven’t previously golfed in C++ so am grateful to all those who helped halve the size ...
Nick Kennedy's user avatar
  • 21.1k
12 votes

Implement Ash's float division

Julia 0.7, 26 bytes imaginary brownie points for using tanh instead of sign (thanks Delfad0r) ...
MarcMush's user avatar
  • 6,505
12 votes

Vanilla Natural Logarithm Challenge

Builtins These answers are in alphabetical order based on programming language. If your answer is identical to an existing one, please combine them. 05AB1E, 4 bytes ...
11 votes

Vanilla Natural Logarithm Challenge

><> (Fish), 71 bytes Trying to solve this in ><> was the original inspiration for this challenge. Posting this now instead of waiting the usual 24 hours to hopefully inspire more ...
mousetail's user avatar
  • 12.6k
10 votes

Bitwise XOR of floats

JavaScript, 47 bytes f=(x,y,k=8**341)=>k&&k*(x<k^y<k)+f(x%k,y%k,k/2) Try it online! k runs through every ...
m90's user avatar
  • 10.5k
10 votes

Vanilla Natural Logarithm Challenge

Hexagony, 161 122 bytes ...
CursorCoercer's user avatar
9 votes

Float 754 to Hamming

Python 3, 72 71 bytes 1 byte thanks to Lynn. lambda n:n and(bin(1020+len(bin(abs(n))))+bin(abs(n))).count('1')-(n>0) Try it online! Explanation The ...
Leaky Nun's user avatar
  • 49.8k
9 votes
Accepted

Float 754 to Hamming

MATL, 5 bytes 3Z%Bz Try it online! Exact transliteration of my MATLAB answer. Note that input and output are implicit. -2 bytes thanks to Luis Mendo. ...
Sanchises's user avatar
  • 9,496
9 votes

Floating Point XOR

ARM Thumb Machine Code, 6 4 Bytes 48 40 70 47 In assembly: EORS R0, R1 ; Exclusive Or of the first two params, store result in the return register BX LR ; Branch to the value stored in the ...
Sir_Lagsalot's user avatar
  • 4,983
9 votes

Implement Ash's float division

R, 98 95 89 88 bytes -6 bytes thanks to Giuseppe function(x,y=abs(scan(t=x)))cat("-"[!!sd(grepl("-",x))],c(z<-y[1]/y[2],!!y)[1+is.na(z)]) ...
Robin Ryder's user avatar
  • 15.6k
9 votes

Cartesian - polar conversion couple

Python, 49 + 48 = 97 bytes -2 thanks to @Seb lambda r,a,n=9e9:((x:=r*(a/n-1j)**n).real,x.imag) Attempt This Online! lambda x,y,n=1e-9:(abs(c:=x+1j*y),(c**n).imag/n) Doesn't use any libraries, no exp, ...
loopy walt's user avatar
  • 16.7k
9 votes

Convert an integer to IEEE 754 float

C (GCC) without reliance on undefined behaviour, 41 40 bytes #define f(x)((union{int a;float b;})x).b Attempt This Online! Type-punning through pointers does ...
Graham's user avatar
  • 191
8 votes

Fast inverse square root

FORTRAN, 124 113 Chars saved 11 Bytes thanks to rafa11111 I know that this question is rather old, but it deserves a FORTRAN answer. It cannot outgolf Perl or Jelly, but it is at least not the worst....
awvwgk's user avatar
  • 81
8 votes

Float 754 to Hamming

C (gcc), 47 bytes f(double n){n=__builtin_popcountl(*(long*)&n);} This isn't portable; it was tested with gcc 7.1.1 on x86_64 running Linux, without compiler ...
Dennis's user avatar
  • 210k
8 votes

Output with the same number of digits of pi as the length of the code

Mathematica, 18 bytes using zeta function Sqrt[6Zeta@2]~N~18 Try it online!
ZaMoC's user avatar
  • 24.9k
8 votes

Display the exponent from a binary floating point number as a decimal value

Python 3, 26 bytes lambda s:int(s[1:9],2)-127 Try it online!
Noodle9's user avatar
  • 20.2k
8 votes

Display the exponent from a binary floating point number as a decimal value

C (gcc), 55 \$\cdots\$ 40 36 bytes Saved 2 6 bytes thanks to ceilingcat!!! Saved 2 a whopping 13 bytes thanks to Arnauld!!! #define f(s)strtol(s+1,s[9]=0,2)-127 ...
Noodle9's user avatar
  • 20.2k
8 votes

Display the exponent from a binary floating point number as a decimal value

Haskell, 33 bytes foldl1(\x y->x*2+y-1).take 8.tail Try it online! Input is a list of integers 0 or 1. It's slightly shorter to ...
lynn's user avatar
  • 68.7k
8 votes

Convert an integer to IEEE 754 float

C++ (GCC / Clang / MSVC), 39 bytes #define f(x)__builtin_bit_cast(float,x) Try it online!
Fulgen's user avatar
  • 181
8 votes

Vanilla Natural Logarithm Challenge

Dyalog APL (no builtin), 13 12 bytes Dyalog does have the builtin , but this way it's more fun :) (⊢-1-÷∘*)⍣=⍨ Basically just ...
RubenVerg's user avatar
  • 802

Only top scored, non community-wiki answers of a minimum length are eligible