source: CIVL/include/impls/int_div.cvl@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 966 bytes
Line 
1#ifndef _INT_DIV_CIVL_
2#define _INT_DIV_CIVL_
3
4$system[civlc] void $assert(_Bool expr, ...);
5$system int $remainder(int x, int y);
6$system int $quotient(int x, int y);
7
8int $int_div(int numerator, int denominator) {
9 if (numerator == 0)
10 return 0;
11 if (numerator >= 0) {
12 if (denominator >= 0)
13 return $quotient(numerator, denominator);
14 else
15 return -$quotient(numerator, -denominator);
16 } else {
17 if (denominator >= 0)
18 return -$quotient(-numerator, denominator);
19 else
20 return $quotient(-numerator, -denominator);
21 }
22}
23
24int $int_mod(int numerator, int denominator) {
25 if (numerator == 0)
26 return 0;
27 if (numerator >= 0) {
28 if (denominator >= 0)
29 return $remainder(numerator, denominator);
30 else
31 return $remainder(numerator, -denominator);
32 } else {
33 if (denominator >= 0)
34 return -$remainder(-numerator, denominator);
35 else
36 return -$remainder(-numerator, -denominator);
37 }
38}
39
40#endif
Note: See TracBrowser for help on using the repository browser.