Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZZZzzzzac committed Sep 27, 2023
1 parent 9cb8ff4 commit e84359f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/arithmetic.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ y = x.mean() <==> numfi(x.double.mean())

ufunc function will use `numfi.double` as operand, then convert to `numfi` object. If `FullPrecision=True`, it will find best fraction precision with floating point result, if not, it will keep same s/w/f as operand.

# How numfi do fixed-point arithmetic
Note this new s/w/f behavior is different from Matlab's, since in Matlab each ufunc has it own `embedded@fi` version, which is not possible in python/numpy.

Example: `np.cos(numfi(0))` is `s16/14` and equal to `1` exactly, which need two integer bit to represent. (remember upper limit of one integer bit is `1 - 2**-f`, not `1`)

But in Matlab `cos(fi(0))` is `s16/15` and equal to `0.999969482421875`. Because Matlab's `cos` function `R2023a\toolbox\fixedpoint\fixedpoint\+embedded\@fi\cos.m` explicitly set answer to `s16/15`. Which make sense since `-1<=cos<=1`, but sacrifice some precision when answer is exactly 1.

## How numfi do fixed-point arithmetic

In theory, to accurately simulate fixed-point arithmetic bit by bit, we should store integers in memory and perform the fixed-point arithmetic in the integer domain. However there are some problems with this approach:

Expand Down
3 changes: 2 additions & 1 deletion docs/class.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# class numfi(numpy.ndarray)

This class is inherited from `numpy.ndarray`, and add some attributes and methods to support fixed-point arithmetic. The main perpose is to mimic Matlab's `fi` object, and
This class is inherited from `numpy.ndarray`, and add some attributes and methods to support fixed-point arithmetic. It's properties and methods are mimic Matlab's `fi` class, make porting code between Matlab and Python easier.(An easy trick is `import numfi as fi`)

## Create new numfi object

```python
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="numfi", # Replace with your own username
version="0.2.4",
version="0.3.0",
author="ZinGer_KyoN",
author_email="[email protected]",
license='MIT',
Expand Down

0 comments on commit e84359f

Please sign in to comment.