bits

gleam add bits
import bits

pub fn main() -> Nil {
  assert Ok(13.37) == bits.to_float(<<"13.37">>)
  assert Ok(1337.0) == bits.to_float(<<"1337">>)
  assert Ok(1337) == bits.to_int(<<"1337">>)

  assert Error(Nil) == bits.to_float(<<"Leet">>)
  assert Error(Nil) == bits.to_int(<<"Leet">>)

  assert <<"13.37">> == bits.from_float(13.37, 2)
  assert <<"1337.0">> == bits.from_float(1337.0, 1)
  assert <<"1337">> == bits.from_int(1337)

  let assert <<code>> = <<" ">>
  assert Ok(8) == bits.find_byte(<<"Icecream Sandwich">>, code)
}

Development

gleam test  # Run the tests

Provenance

The project only contains artisanal code. No AI generation or assistance is used to implement any functionality.

LICENSE

bits is made available under the terms of the EUPL-1.2 License.

✨ Search Document