Making a WebAssembly interpreter in Ruby, part 8: refactoring floating-point encoding

Опубликовано: 08 Август 2026
на канале: Tom Stuart
152
5

https://github.com/tomstuart/wasminna...

00:00:00 — Waiting to start
00:00:41 — Hello
00:02:29 — Retro
00:04:32 — Lift `numerator` and `denominator` assignment out of conditional
00:13:58 — Extract Wasminna::Float::Format class
00:31:48 — Use ranges for valid significands and exponents
00:41:39 — Use Range#include? to keep exponent in range
00:42:51 — Reorder #scale_significand arguments
00:45:03 — Rename #scale_significand to #scale_quotient
00:49:03 — Extract #significands and #exponents into Wasminna::Float::Format
00:53:42 — Remove redundant special case for zero numerator in #encode
00:57:01 — Extract #round_quotient from #encode
01:03:40 — Clean up #round_quotient to make its purpose clearer
01:05:17 — Extract #scale_and_round_quotient method
01:09:12 — Inline initial exponent in #encode
01:11:10 — Extract Approximation class to deal with scaling and rounding of quotient
01:27:48 — Extract #approximate_within helper method
01:32:09 — Remove redundant `numerator` and `denominator` local variables
01:33:04 — Rename Approximation methods to say `_within`
01:36:08 — Remove weak-sauce comment
01:36:47 — Use explicit min/max exponent for subnormal/infinite results
01:38:50 — Delegate to Infinite#encode in Finite#encode when the significand is too large
01:40:58 — Return correct range of exponents from Format#exponents
01:50:20 — Extract Format#pack from #encode
02:10:13 — Extract format#unpack from Float.decode
02:15:02 — Rewrite Format#pack to look more like #unpack
02:19:50 — Make Format#pack and #unpack deal with the negated boolean, not the sign bit
02:24:07 — Make Format#pack and #unpack deal with unbiased exponents
02:30:25 — Don’t care about exponent when decoding zero
02:40:12 — Remove exponent bias entirely in #decode
02:48:50 — Make Wasminna::Float::Format#exponent_bias private
02:50:23 — Use #mask helper in Wasminna::Float
02:53:55 — Pass `format`, not `bits`, into Float.decode and #encode
03:03:20 — Replace if/elsif with case on `exponent` in #decode
03:04:38 — Use Wasminna::Float in #interpret_float
03:29:24 — Pass `format`, not `bits`, into #interpret_float
03:30:13 — Move Interpreter#interpret_float to Wasminna::Float.parse
03:33:27 — Move #encode out of Wasminna::Float.parse
03:36:26 — Introduce INFINITE_REGEXP so that all float types have their own regexp
03:40:18 — Match sign explicitly in float regular expressions
03:46:29 — Set radix, base and exponent_radix explicitly when parsing finite floats
03:50:56 — Combine hex and decimal float parsing cases
03:59:48 — Deconstruct MatchData directly in pattern matches in Float.parse
04:10:16 — Extract exponent sign separately in Float.parse
04:18:02 — Use safe navigation instead of relying on nil.to_s.to_i in Float.parse
04:23:28 — Match float syntaxes starting with the most likely ones
04:29:52 — Implement #to_f on Wasminna::Float instances
04:47:27 — Use Wasminna::Float everywhere in interpreter
04:47:51 — Wrapping up
04:51:20 — Bye