summaryrefslogtreecommitdiff log msg author committer range
path: root/include/libcss/fpmath.h
blob: 0e314cbdb8d6757d6a4dedac5d6194ff1c4390f5 (plain)
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 ``` ``````/* * This file is part of LibCSS. * Licensed under the MIT License, * http://www.opensource.org/licenses/mit-license.php * Copyright 2008 John-Mark Bell */ #ifndef libcss_fpmath_h_ #define libcss_fpmath_h_ #include /* 22:10 fixed point math */ typedef int32_t css_fixed; /* Add two fixed point values */ #define FADD(a, b) ((a) + (b)) /* Subtract two fixed point values */ #define FSUB(a, b) ((a) - (b)) /* Multiply two fixed point values */ #define FMUL(a, b) (((a) * (b)) >> 10) /* Divide two fixed point values */ #define FDIV(a, b) (((a) << 10) / (b)) /* Add an integer to a fixed point value */ #define FADDI(a, b) ((a) + ((b) << 10)) /* Subtract an integer from a fixed point value */ #define FSUBI(a, b) ((a) - ((b) << 10)) /* Multiply a fixed point value by an integer */ #define FMULI(a, b) ((a) * (b)) /* Divide a fixed point value by an integer */ #define FDIVI(a, b) ((a) / (b)) /* Convert a floating point value to fixed point */ #define FLTTOFIX(a) ((fixed) ((a) * (float) (1 << 10))) /* Convert a fixed point value to floating point */ #define FIXTOFLT(a) ((float) (a) / (float) (1 << 10)) /* Convert an integer to a fixed point value */ #define INTTOFIX(a) ((a) << 10) /* Convert a fixed point value to an integer */ #define FIXTOINT(a) ((a) >> 10) /* Useful values */ #define F_PI_2 0x00000648 /* 1.5708 (PI/2) */ #define F_PI 0x00000c91 /* 3.1415 (PI) */ #define F_3PI_2 0x000012d9 /* 4.7124 (3PI/2) */ #define F_2PI 0x00001922 /* 6.2831 (2 PI) */ #define F_90 0x00016800 /* 90 */ #define F_180 0x0002d000 /* 180 */ #define F_270 0x00043800 /* 270 */ #define F_360 0x0005a000 /* 360 */ #define F_100 0x00019000 /* 100 */ #define F_200 0x00032000 /* 200 */ #define F_300 0x0004b000 /* 300 */ #define F_400 0x00064000 /* 400 */ #endif ``````