Code Monkey home page Code Monkey logo

fpc's Introduction

Fixed-point Calculator

This program takes a range [min, max] and precision and calculates constants and information to be used in code performing calculations in this range using fixed-point integer math.

This is not an official Google product.

Try it!

$ git clone ssh://[email protected]:7999/user/fpc.git
$ make
$ ./fpc -g 30 1800 0.1
[PARAMETERS]
  min: 30 (30 requested)
  max: 1800 (1800 requested)
  precision: 0.0625 (0.1 requested)

[CODE]
  code density: 62.5%
  offset: 0
  code range: [480, 28800]

[ENCODING]
  machine bit width: 16 (15 used)
    fractional bits: 4
    integer bits: 11
  use signed: no
  machine integer type: uint16_t
  Q notation: Qu12.4

[CONVERSION]
#include <math.h>
#include <stdint.h>
// can lose precision, for display only
double convert_to_double(uint16_t x) {
  if(x < UINT16_C(480) &&
     x > UINT16_C(28800)) {
    return NAN;
  }
  return round(ldexp(x, -4) * 10) * 0.1;
}
$ make convert
$ ./convert 480 600 10000 28800
480 -> 30
600 -> 37.5
10000 -> 625
28800 -> 1800

Also, check this out:

$ ./fpc -2^7 -l-p 2^-8
[PARAMETERS]
  min: -128 (-128 requested)
  max: 127.99609375 (127.99609375 requested)
  precision: 0.00390625 (0.00390625 requested)
...

fpc has an expression evaluator built in to allow simple expressions!

  • supports (in order of precedence)
    • parenthesis: (x)
    • exponentiation: x ^ y
    • multiply: x * y, divide: x / y
    • addition: x + y, subtraction: x - y
  • some variables
    • min: l
    • max: h
    • precision: p

fpc's People

Stargazers

 avatar

Watchers

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