This repository has been archived by the owner. It is now read-only.
hexfloat.cr
hexfloat.cr
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.
Installation
-
Add the dependency to your
shard.yml
:dependencies: hexfloat: github: HertzDevil/hexfloat.cr
-
Run
shards install
Usage
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
Contributing
- 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
Contributors
- Quinton Miller - creator and maintainer
Repository
hexfloat.cr
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- 11 months ago
- November 16, 2021
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 13:12:44 GMT
Languages