Giter Site home page Giter Site logo

posit.jl's Introduction

SoftPosit.jl

CI DOI

A pure Julia implementation for posit arithmetic. Posit numbers are an alternative to floating-point numbers. Posits extend floats by introducing regime bits that allow for a higher precision around one, yet a wide dynamic range of representable numbers. For further information see posithub.org.

v0.5 respects the 2022 Standard for Posit Arithmetic but drops quire support. v0.4 implements the previous standard, has quire support but depends on the C implementation of SoftPosit.

If this library doesn't support a desired functionality or for anything else, please raise an issue.

Installation

In the Julia REPL do

julia>] add SoftPosit

where ] opens the package manager. Then simply using SoftPosit which enables all of the functionality.

8, 16 and 32bit posit formats

SoftPosit.jl emulates the following Posit number formats Posit(n,es), with n number of bits including es exponent bits: Posit(8,2), Posit(16,2) and Posit(32,2) called

Posit8, Posit16, Posit32

as well as the off-standard format Posit(16,1) called Posit16_1 as part of the previous posit arithmetic draft standard.

For all the formats conversions between integers and floats and basic arithmetic operations +, -, *, / and sqrt (among others) are defined.

Examples

Conversion to and from Float64 and computing a square root

julia> using SoftPosit
julia> p = Posit16(16)
Posit16(16.0)

julia> sqrt(p)
Posit16(4.0)

And the bitwise representation split into sign, regime, exponent and mantissa bits using bitstring(p,:split)

julia> bitstring(Posit32(123456.7),:split)
"0 111110 00 11100010010000001011010"

For an (outdated) comprehensive notebook covering (almost) all the functionality of SoftPosit.jl please read softposit_examples.ipynb

Rounding mode

Following the 2022 posit standard, posits should never underflow nor overflow. This is in v0.5 generally respected, but there are some caveats: Posits currently do underflow below about 4*floatmin of the float format you are converting from. In practice this is of little importance as even floatmin(::PositN)^2 is larger than that

julia> floatmin(Posit16)
Posit16(1.3877788e-17)

julia> floatmin(Posit16)*floatmin(Posit16)
Posit16(1.3877788e-17)

and similar for other posit formats. So in Posit16 arithmetic we have 1e-17*1e-17 = 1e-17 (no underflow) and 1e17*1e17 = 1e17 (no overflow).

posit.jl's People

Contributors

milankl avatar giordano avatar adamryczkowski avatar juliatagbot avatar waldyrious avatar

Watchers

James Cloos 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.