fixedpoint
Version, currently master branch1 version
- master branchlatestMay 16, 2021
github.com/Groogy/fixedpoint
Crystal implementation of fixed point arithmetics
Installation
# Add this to your shard.yml
dependencies:
fixedpoint:
github: Groogy/fixedpoint
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
1.0.0- License
- MIT
- Author
- Groogy
Dependencies
This version declares no dependencies.
README
fixedpoint
Implements fixed point arithmetics.
Installation
-
Add the dependency to your
shard.yml:dependencies: fixedpoint: github: Groogy/fixedpoint -
Run
shards install
Usage
To include the fixed point structure you have to write this to get started.
require "fixedpoint"
include FP
Everything is defined in the FP namespace, it's optional to mixin the module but highly recommended. It provides some shortcut to also make things easier to work with.
FP::FixedPoint(Underlying, Scale)is the struct that represents a fixed point value. Underlying is what underlying data type it will use while Scale is what it will scale that value with.FP::FixedPoint32is an alias for FixedPoint(Int32, 1_000) and have a range of -2 147 483.648 to 2 147 483.647 with a precision of 3 digitsFP::FixedPoint64is an alias for FixedPoint(Int64, 1_000_000) and have a range of -9 223 372 036 854.775808 to -9 223 372 036 854.775807 with a precision of 6 digits.FP.fp32(Number)is a shortcut function to construct aFixedPoint32value from the given numberFP.fp64(Number)is a shortcut function to construct aFixedPoint64value from the given numberFP.fp(Number)is a shortcut function but will construct a FixedPoint based of the size of the given number.
Future Development
Right now this uses a very naive implementation that does a lot of division meaning a bit slower performance, also limits the range a bit more than other solutions would, especially when it comes to multiplication. So next step should be to do a different kind of implementation that performs better and that let's us use the built-in LLVM operators for fixed point arithmetics.
Contributing
- Fork it (https://github.com/Groogy/fixedpoint/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
- Groogy - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- May 16, 2021
- Crystal
1.0.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/Groogy/fixedpoint
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 16, 2026
- Synced
- Aug 16, 2026
- Versions
- 1