Last active
April 18, 2020 02:06
-
-
Save qhwa/5a5827857bf7c0424cbe9d418db99b4c to your computer and use it in GitHub Desktop.
BitString decomposing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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