diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-03-26 17:29:33 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-11-18 14:03:26 +0100 |
| commit | 25dbd228c11410218242e585c598697005c707ea (patch) | |
| tree | 4371572c4e7f05fb61720b950250cc7821b48b27 /validation/backend/arithmetic-ops.c | |
| parent | 1c182507c3981aa20193c68d7cfd32d750b571cf (diff) | |
| download | sparse-dev-25dbd228c11410218242e585c598697005c707ea.tar.gz | |
add support of floating-point specific arithmetic ops
Floating-point arithmetic is quite different from the
arithmetic on integers or the one of real numbers.
In particular, most transformations, simplifications that can
be done on integers are invalid when done on floats.
For example:
- associativity doesn't hold
- distributivity doesn't hold
- comparison is tricky & complex
This is because (among others things):
- limited precision, rounding everywhere
- presence of signed zeroes
- presence of infinities
- presence of NaNs (signaling or quiet)
- presence of numbers without inverse
- several kind of exceptions.
Since they don't follow the same rules as their integer
counterpart, better to give them a specific opcode
instead of having to test the type of the operands at
each manipulation.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/backend/arithmetic-ops.c')
| -rw-r--r-- | validation/backend/arithmetic-ops.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/validation/backend/arithmetic-ops.c b/validation/backend/arithmetic-ops.c index 55996d9c..fc4f0e5a 100644 --- a/validation/backend/arithmetic-ops.c +++ b/validation/backend/arithmetic-ops.c @@ -88,6 +88,26 @@ static unsigned int umod(unsigned int x, unsigned int y) return x % y; } +static int neg(int x) +{ + return -x; +} + +static unsigned int uneg(unsigned int x) +{ + return -x; +} + +static float fneg(float x) +{ + return -x; +} + +static double dneg(double x) +{ + return -x; +} + /* * check-name: Arithmetic operator code generation * check-command: sparsec -c $file -o tmp.o |
