var x = (4 * y) + "px";

Thomas Depierre

haruspex.dev

@Di4naO

floating-point constant

float-to-string conversion

floating-point multiplication

string concatenation

0.3
0

sign

exponent

mantissa

(-1)^s * (1.mantissa)2 * 2^(exponent-bias)
01101
0011001101
0.300048828125

exactly

0

sign

exponent

mantissa

01101
0011001101
0.300048828125

exactly

0.2999267578125
0.3001708984375
0.300048828125
0.3?
  • Dragon4 (Steele and White, 1990)
    • Slow (uses bignums), complete
    • Improved by Gay (1990), Burger and Dybvig(1996)
  • Grisu2 (Loitsch, 2010 intermediate result)
    • Incorrect output don't use!
  • Grisu3 (Loitsch, 2010)Fast, incomplete (needs fallback algorithm)
  • Errol3 (Andrysco, Jhala, and Lerner, 2016)
    • Moderate speed, complete
  • Ryu (Ulf Adams, 2018)
    • Fastest, complete

Solutions

Most libc and stdlib

SUPER FAST

 Name           ips        average  deviation         median         99th %
Ryu          80.26       12.46 ms     ±7.14%       12.19 ms       14.98 ms
OTP          25.36       39.43 ms    ±14.13%       38.02 ms       62.33 ms
Comparison: 
Ryu          80.26
OTP          25.36 - 3.16x slower +26.97 ms

 

SUPER FAST

Sources

String that float

By di4nao

String that float

Lightning talk Codemesh 2020

  • 548