项目作者: carpentry-org

项目描述 :
Rational numbers for Carp
高级语言:
项目地址: git://github.com/carpentry-org/rational.git
创建时间: 2018-11-05T09:56:13Z
项目社区:https://github.com/carpentry-org/rational

开源协议:MIT License

下载


rational

Rational numbers (a.k.a fractions) for Carp.

Fractions are expressed as pairs of integers. Mathematical operations and
conversion primitives to and from integers and floating point numbers are
provided.

Installation

  1. (load "git@github.com:carpentry-org/rational@0.4")

Usage

  1. (load "git@github.com:carpentry-org/rational@0.3")
  2. (Rational.new 22 12) ; => (Rational 11/6)
  3. (Rational.mul (Rational.new 22 12) (Rational.new 1 6)) ; => (Rational 2/1)
  4. (Rational.to-int (Rational.new 2 1)) ; => 2
  5. (Rational.to-float (Rational.new 1 4)) ; => 0.25

Please note that conversion can be lossy, because conversion to integer throws
away any non-real value and conversion to floating point values is only as
accurate as floating point numbers are.


Have fun!