Giter VIP home page Giter VIP logo

float24's Introduction

/* float24, Copyright (c) 2020 Yuriy Yakimenko */ 

####  Floating point number using 24 bits.
=========================================

I needed  to store a floating point value  with maximum possible  precision, but
had  only  three bytes (as opposed to regular four) for it in memory. I am aware
of 16-bit floats (aka mini-floats or half-floats) but I wanted to take advantage
of using all three bytes for best accuracy. 

In my  case I needed to store non-negative numbers between 0 and  65536  (2^16),
which made a decision  of how many bits to  allocate  for mantissa and  exponent
very simple. Since I did not  need negative  values, I also did  not need a sign
bit. 

With maximum value of 2^16 I needed to allocate 5 bits for exponent (effectively
storing values from -15 (corresponds to 1) to 15 (corresponds to 31)). Note that
when   exponent   bits    contain    zero,   we    store   denormalized   number
(https://en.wikipedia.org/wiki/Denormal_number). 

I   also  made   this  implementation  compatible   with  both  big-endian   and
little-endian machines. 

#### Update to support signed 24-bit floats:
===========================================

To represent  signed 24-bit  number,  use float24_s structure. It  uses the same
number of  bits  for exponent but one  bit for sign, and correspondingly 18, not
19 bits for mantissa. 

#### Known issues: 
================= 

In case  you  would  like  to modify this code to store  a  different range, you 
will need  to change the number of exponent bits accordingly using FP24_EXP_BITS 
or FP24S_EXP_BITS. Everything else is done automatically. 

License

MIT

float24's People

Contributors

intheswim 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.