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
RevLine 
[906465c]1#ifndef _INT_DIV_CIVL_
2#define _INT_DIV_CIVL_
3
[25507974]4$system[civlc] void $assert(_Bool expr, ...);
[ad6ea7c]5$system int $remainder(int x, int y);
6$system int $quotient(int x, int y);
[906465c]7
8int $int_div(int numerator, int denominator) {
9 if (numerator == 0)
10 return 0;
11 if (numerator >= 0) {
12 if (denominator >= 0)
[ad6ea7c]13 return $quotient(numerator, denominator);
[906465c]14 else
[ad6ea7c]15 return -$quotient(numerator, -denominator);
[906465c]16 } else {
17 if (denominator >= 0)
[ad6ea7c]18 return -$quotient(-numerator, denominator);
[906465c]19 else
[ad6ea7c]20 return $quotient(-numerator, -denominator);
[906465c]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)
[ad6ea7c]29 return $remainder(numerator, denominator);
[906465c]30 else
[ad6ea7c]31 return $remainder(numerator, -denominator);
[906465c]32 } else {
33 if (denominator >= 0)
[ad6ea7c]34 return -$remainder(-numerator, denominator);
[906465c]35 else
[ad6ea7c]36 return -$remainder(-numerator, -denominator);
[906465c]37 }
38}
39
40#endif
Note: See TracBrowser for help on using the repository browser.