Git Product home page Git Product logo

forth-rat-math-lib's Introduction

Rational Math Library for Forth

This repository provides a library to do basic arithmetic with highly precise rational numbers and to convert between rational numbers and the usual number types supported by Forth.

Rational numbers are expressed as fractions with a single-precision signed integer numerator and single-precision signed integer denominator.

Rational numbers are able to exactly express many “floating point” decimal numbers that cannot be expressed exactly as fixed or floating point numbers. For example, 0.1 can only be approximately expressed as a floating or fixed point number but can be exactly expressed as a rational number: 1/10.

This library supports 2-cell rational numbers consisting of a single-precision signed numerator and a single-precision unsigned denominator.

The largest number that can be expressed is the same as a single-precision signed integer (2,147,483,647 with a 32-bit cell), with 1 in the denominator. The smallest fraction that can be expressed is the inverse of the largest single-precision signed integer (1/2147483647), with 1 (or -1) in the numerator and the maximum integer in the denominator.

There is an inherent trade-off between precision and range. Precision and range vary inversely to each other depending on the size of the denominator. If the denominator is at the minimum, 1, the range is the entire single-precision integer range (-2,147,483,648 to 2,147,483,647) but there is only integer precision. If the denominator is 1000, there is 0.001 precision, but 1/1000 of the single-precision integer range (-2,147,483 to 2.147,483). When the denominator is at its maximum, precision is very high and the range is reduced to -1 to 1.

I realize that the limited range may be a concern for some applications. I intend to address the range issue by creating a 3-word “mixed rational” type that includes a single-precision integer and a single-precision rational. This will expand the range to the entire single-precision integer range while retaining full rational precision.

forth-rat-math-lib's People

Contributors

daniel-birket avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.