zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

float4.ex (818B)


      1 defmodule Postgrex.Extensions.Float4 do
      2   @moduledoc false
      3   import Postgrex.BinaryUtils, warn: false
      4   use Postgrex.BinaryExtension, send: "float4send"
      5 
      6   def encode(_) do
      7     quote location: :keep do
      8       n when is_number(n) ->
      9         <<4::int32(), n::float32()>>
     10 
     11       :NaN ->
     12         <<4::int32(), 0::1, 255, 1::1, 0::22>>
     13 
     14       :inf ->
     15         <<4::int32(), 0::1, 255, 0::23>>
     16 
     17       :"-inf" ->
     18         <<4::int32(), 1::1, 255, 0::23>>
     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       <<4::int32(), 0::1, 255, 0::23>> -> :inf
     28       <<4::int32(), 1::1, 255, 0::23>> -> :"-inf"
     29       <<4::int32(), _::1, 255, _::23>> -> :NaN
     30       <<4::int32(), float::float32()>> -> float
     31     end
     32   end
     33 end