https://github.com/hellerve/silly
A silly implementation of fixed point arithmetic (mirror because I linked here on my blog)
https://github.com/hellerve/silly
Last synced: 12 months ago
JSON representation
A silly implementation of fixed point arithmetic (mirror because I linked here on my blog)
- Host: GitHub
- URL: https://github.com/hellerve/silly
- Owner: hellerve
- Created: 2020-06-23T18:31:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-23T18:31:40.000Z (over 5 years ago)
- Last Synced: 2025-02-12T05:12:03.413Z (about 1 year ago)
- Language: C
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# silly
A toy library implementing fixed-point arithmetic.
Please don’t use it, the name is descriptive.
It’s also pretty inefficient.
## Installation
Don’t. The makefile only includes a test target, because I want to test my code.
## Usage
```c
silly silly_zeros(); // creates a fixed point value of zero
silly make_silly(short, int, int); // make a silly number from the triple (negative?, before decimal, after)
silly silly_from_float(float); // creates a silly number from a float
silly silly_from_double(double); // creates a silly number from a double
double silly_to_double(silly); // convert a silly number into a double
uint64_t silly_to_uraw(silly); // convert the silly struct to a raw value (without sign)
int64_t silly_to_raw(silly); // convert the silly struct to a raw value (with sign)
silly silly_add(silly, silly); // addition
silly silly_sub(silly, silly); // subtraction
silly silly_mul(silly, silly); // multiplication
silly silly_idiv(silly, silly); // division (integer precision)
silly silly_div(silly, silly); // division
char* silly_to_string(silly); // converts a fixed point value to a string (memory is now yours)
```
That's it!
Have fun!