package

codeberg.org/elliethepuppy/fractional

main / published Jun 11, 2026 / repository

a fractional arithmetic library for crystal

Fractional

A Crystal library for working and doing math with fractions.

Installation

To install this library, first add the dependency to your shard.yml:

...
dependencies:
  fractional:
    codeberg: elliethepuppy/fractional
...

Then run shards install and there you go!

Usage

To use this library, first require it in your project:

require "fractional"

Then, simply create and operate on some fractions. The standard syntax for creating a fraction is to use the frac(numerator, denominator) macro. This macro acts effectively as a literal for the type.

two_over_three = frac(2, 3) # equivalent to: two_over_three = Fractional.new 2, 3
two_over_three + frac(5, 3) # => 7/3

Further details can be found in the documentation (located in the source code, as well as available as a website by building using crystal docs).

Contributing

  1. Clone the repo (git clone https://codeberg.org/elliethepuppy/fractional.git)
  2. Create your feature branch (git checkout -b <your-descriptive-feature-name>)
  3. Make your changes, then add any new files and commit your changes (git add [files...]; git commit -am "your comment")
    • Be sure to write your own tests! And make sure they pass! No tests, no apply!
  4. Create a patch against the main branch (git diff main > <your-descriptive-feature-name>.patch)
  5. Send me an email whose subject begins with "[GIT/Fractional] (YOUR DESCRIPTIVE FEATURE NAME)" and whose body contains a descriptive explanation of what your feature is and why it's good.
  6. Sit back and wait! I'll send you an email when/if I merge your changes.

DO NOT OPEN PULL REQUESTS

Contributors

  • ellie - creator and maintainer

API

  • Fractional

    Fractional is a library that implements fractions and fractional arithmetic in Crystal beyond purely rational numbers (as is possible in the standard library with BigRational).

  • Number

    This is the built-in base type for all numbers.