Created
April 5, 2023 17:26
-
-
Save Nezteb/d36f151524cdb21a779b595ab192974a to your computer and use it in GitHub Desktop.
By ChatGPT using GPT-4
This file contains 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
# "please implement the frexp function in elixir, and minify it as much as possible" | |
defmodule Decode do | |
use Bitwise | |
@b 1022 | |
def frexp(v), do: <<s::1, e::11, f::52>> = <<v::float>>; frexp(s, f, e) | |
defp frexp(_, 0, 0), do: {0.0, 0} | |
defp frexp(s, f, 0), do: exp = bl(f); <<r::float>> = <<s::1, @b::11, (f-1)::52>>; {r, -(@b) - 52 + exp} | |
defp frexp(s, f, e), do: <<r::float>> = <<s::1, @b::11, f::52>>; {r, e - @b} | |
def bl(v), do: bl(v, 0) | |
defp bl(0, n), do: n | |
defp bl(v, n), do: bl(bsr(v, 1), n+1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment