Skip to content

Instantly share code, notes, and snippets.

@qhwa
Last active April 18, 2020 02:06
Show Gist options
  • Save qhwa/5a5827857bf7c0424cbe9d418db99b4c to your computer and use it in GitHub Desktop.
Save qhwa/5a5827857bf7c0424cbe9d418db99b4c to your computer and use it in GitHub Desktop.
BitString decomposing
defmodule IEEE_754 do
def friction_to_mantissa(""), do: 0
def friction_to_mantissa(<<n::1, rest::bits>>),
do: n + friction_to_mantissa(rest) * 0.5
end
iex> mantissa = IEEE_754.friction_to_mantissa(<<1::1, friction::bits>>)
...> :math.pow(-1, sign) * mantissa * :math.pow(2, exponent - 1023)
3.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment