Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Kotlin
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.idea
src
.gitignore
README.md
RationalNumber.iml
pom.xml

README.md

kotlin-rational

This is a simple rational number class for the Kotlin programming language. It can be used to represent any number that can be expressed as one integer divided by another. It has the advantage that, unlike Floats or Doubles, it will not lose precision.

It takes advantage of Kotlin's operator overloading to allow you to use these Rational numbers as if they were primitive types. Rational numbers are immutable.

How do I install kotlin-rational

QuickDT is distributed using Maven. To use it in your project just add this repository to your pom.xml file:

        <repository>
            <id>sanity-maven-repo</id>
            <name>Sanity's Maven repository on GitHub</name>
            <url>http://sanity.github.com/maven-repo/repository/</url>
        </repository>

And this dependency:

        <dependency>
            <groupId>us.locut</groupId>
            <artifactId>RationalNumber</artifactId>
            <version>1.03</version>
        </dependency>

Usage example

Rational(1, 2) + Rational(1, 4)
Rational(5, 6) * 3
println(Rational(2, 6)) // This will print "1/3" because we always simplify if we can
Rational(2, 3) > Rational(3, 4)

See RationalTest.kt for more usage examples.

License

Copyright 2012 Ian Clarke.

Licensed under the Apache License, Version 2.0 (the "License"), you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Something went wrong with that request. Please try again.