This shard is now archived as the functionality is now available in Crystal 1.11 since crystal-lang/crystal#14027.
Provides conversion functions between hexadecimal floating-point literals and floating-point values.
-
Add the dependency to your
shard.yml
:dependencies: hexfloat: github: HertzDevil/hexfloat.cr
-
Run
shards install
require "hexfloat"
HexFloat.to_f64("0x12.34p+5") # => 582.5
HexFloat.to_f32("0x3.333334p+1") # => 6.4_f32
HexFloat.to_f("0x12.34p+5") # => 582.5
HexFloat.to_f("0x12.34p+5f32") # => 582.5_f32
HexFloat.to_s(6.125) # => "0x1.88p+2"
HexFloat.to_s(-1_f32 / 3) # => "-0x1.555556p-2"
String.build do |io|
HexFloat.to_s(io, 6.125)
HexFloat.to_s(io, -1_f32 / 3)
end
- Fork it (https://github.com/HertzDevil/hexfloat.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Quinton Miller - creator and maintainer