No description
Find a file
lbartoletti bd1e1da0e6 Merge branch 'fpn_lut' into 'main'
Add LookUp Table

See merge request lbartoletti/fpn!12
2025-04-08 21:32:10 +02:00
src feat(lookuptable): improve benchmarks and new functions 2025-03-30 22:06:12 +02:00
tests tests(lookuptable): rewrite tests 2025-04-08 21:00:36 +02:00
.gitignore add test bin in gitignore 2021-10-26 22:08:57 +02:00
.gitlab-ci.yml update CI with cocoverage 2021-10-26 22:12:42 +02:00
CHANGELOG Add CHANGELOG 2021-10-26 21:12:34 +00:00
config.nims feat(lookuptable): improve benchmarks and new functions 2025-03-30 22:06:12 +02:00
fpn.nimble chore(test): Use danger to avoid overflow check 2025-04-08 20:57:55 +02:00
LICENSE Add LICENSE 2020-10-07 20:46:53 +00:00
README.md add link to api 2020-10-07 22:36:32 +02:00

NIM Fixed Point Number library

fpn is a library for fixed point number in NIM.

It offers a similar interface to the standard math functions for use on fixed point numbers.

You can create fpn type with genQM_N(fpn_type, n_fract_bits, type

  • fpn_type is the name of your type (ex. initQ16_16)
  • n_fract_bits the number of fractional bits stored
  • type between fixedPoint8, fixedPoint16, fixedPoint32, fixedPoint64

Example

Add two numbers:

var a = initQ16_16()
var b = initQ16_16()

a.fromFloat(40.4)
b.fromFloat(1.6)
echo add(a, b).toInt()
# 42

Create a new fpn type:

genQM_N(initQ4_12, 12, fixedPoint16)
var q = initQ4_12()
q.toInt() # 0 == type int16
# q.fromFloat(4.2)
echo q.toInt() # 4 == type int16
echo q # (data: 17203) == type fixedPoint16[12]
echo q.toFloat() # 4.199951171875 == type float

See tests for more example.

API Documentation

Documentation is available at https://lbartoletti.gitlab.io/fpn/fpn.html

How to contribute?

There is a TODO list if you wish to contribute. Improve existing documentation and tests. Please document new methods and provide a test for them.

PR are welcomed!

TODO

  • A full README :)
  • Add build Options (no float / max 8-16-32 bits ...)
  • Trigonometry functions (cordic in progress in another library ; maybe LUT and Taylor series in another library)
  • More tests (only Q16_16 is tested)
  • Bindings (C and Python planned)