Coder Social home page Coder Social logo

sgpositpy's Introduction

sgpositpy

Join the chat at https://gitter.im/sgpositpy/Lobby

sgpositpy regression test status on Travis CI

sgpositpy regression test status on Appveyor

sgpositpy under MIT license

Posit is a new binary format for representing decimal numbers, an alternative to IEEE 754 floating-point number. Different configurations on the number bit size and the scaling are possible. Details can be found at the posithub and the notebook on posit.

We are interested to experiment with different posit configurations the nbits and the es sizes, and attempt to use smaller bit sizes in our applications while achieving the required accuracy to operate. However, an implementation conforming to the posit design is still lacking for popular programming languages.

This project, sgpositpy, is our attempt to develop a prototype implementation that is correct by the posit design. This can then serve as a reference for subsequent development of performance optimized posit library. Hence, the computation efficiency is currently not the focus of the project.

Current status

The current implementation is research oriented and experimental at pre-alpha stage. This is NOT currently suitable for production use.

Install

Install from PyPI

$ pip install sgposit

Install from code repository

$ git clone https://github.com/xman/sgpositpy
$ cd sgpositpy
$ pip install -r requirements.txt
$ python setup.py install

# Run regression tests.
$ python setup.py test

# Enable long running tests.
$ SGPOSIT_LONG_TESTS=1 python setup.py test

Getting started

The PCPosit class is our reference implementation with extensive regression tests. We shall have performance optimized version in Posit class for general use in the future.

The following code snippet creates posit objects from the given bit patterns, and the posit configuration, nbits and es.

# file: samples/pcposit_sample.py

from sgposit.pcposit import PCPosit

a = PCPosit(0x0C, mode='bits', nbits=6, es=2)
b = PCPosit(0x0F, mode='bits', nbits=6, es=2)

c = a + b
print("{} + {} => {}".format(a, b, c))

d = a - b
print("{} - {} => {}".format(a, b, d))

e = a * b
print("{} * {} => {}".format(a, b, e))

f = a / b
print("{} + {} => {}".format(a, b, f))

g = -a
print("uminus {} => {}".format(a, g))
$ python samples/pcposit_sample.py
1/4 + 3/4 => 1
1/4 - 3/4 => -1/2
1/4 * 3/4 => 3/16
1/4 / 3/4 => 3/8
uminus 1/4 => -1/4

License

sgpositpy is licensed under MIT License.

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.