Skip to content

Instantly share code, notes, and snippets.

@Nezteb
Created April 5, 2023 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nezteb/d36f151524cdb21a779b595ab192974a to your computer and use it in GitHub Desktop.
Save Nezteb/d36f151524cdb21a779b595ab192974a to your computer and use it in GitHub Desktop.
By ChatGPT using GPT-4
# "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