float8.ex (848B)
1 defmodule Postgrex.Extensions.Float8 do 2 @moduledoc false 3 import Postgrex.BinaryUtils, warn: false 4 use Postgrex.BinaryExtension, send: "float8send" 5 6 def encode(_) do 7 quote location: :keep do 8 n when is_number(n) -> 9 <<8::int32(), n::float64()>> 10 11 :NaN -> 12 <<8::int32(), 0::1, 2047::11, 1::1, 0::51>> 13 14 :inf -> 15 <<8::int32(), 0::1, 2047::11, 0::52>> 16 17 :"-inf" -> 18 <<8::int32(), 1::1, 2047::11, 0::52>> 19 20 other -> 21 raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, "a float") 22 end 23 end 24 25 def decode(_) do 26 quote location: :keep do 27 <<8::int32(), 0::1, 2047::11, 0::52>> -> :inf 28 <<8::int32(), 1::1, 2047::11, 0::52>> -> :"-inf" 29 <<8::int32(), _::1, 2047::11, _::52>> -> :NaN 30 <<8::int32(), float::float64()>> -> float 31 end 32 end 33 end