Skip to content

Commit

Permalink
adapt code to agree with ANSI C for the msvc compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Aug 31, 2015
1 parent a481fe6 commit 68b4a60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
29 changes: 15 additions & 14 deletions SimulationRuntime/c/util/rational.c
Expand Up @@ -29,6 +29,13 @@
*/

#include "rational.h"
#include "omc_msvc.h"

RATIONAL makeRATIONAL(long a, long b)
{
RATIONAL x = {a, b};
return x;
}

static long long gcd(long long a, long long b)
{
Expand All @@ -52,55 +59,49 @@ RATIONAL addInt2Rat(long a, RATIONAL b) {
long long m = (long long)a * b.n + b.m;
long long n = b.n;
simplifyRat(&m, &n);
RATIONAL x = {m, n};
return x;
return makeRATIONAL(m, n);
}

RATIONAL subInt2Rat(long a, RATIONAL b) {
long long m = (long long)a * b.n - b.m;
long long n = b.n;
simplifyRat(&m, &n);
RATIONAL x = {m, n};
return x;
return makeRATIONAL(m, n);
}

RATIONAL addRat2Rat(RATIONAL a, RATIONAL b) {
long long m = (long long)a.m * b.n + (long long)b.m * a.n;
long long n = (long long)a.n * b.n;
simplifyRat(&m, &n);
RATIONAL x = {m, n};
return x;
return makeRATIONAL(m, n);
}

RATIONAL multRat2Rat(RATIONAL a, RATIONAL b) {
long long m = (long long)a.m * b.m;
long long n = (long long)a.n * b.n;
simplifyRat(&m, &n);
RATIONAL x = {m, n};
return x;
return makeRATIONAL(m, n);
}

RATIONAL divRat2Rat(RATIONAL a, RATIONAL b) {
long long m = (long long)a.m * b.n;
long long n = (long long)a.n * b.m;
simplifyRat(&m, &n);
RATIONAL x = {m, n};
return x;
return makeRATIONAL(m, n);
}

RATIONAL multInt2Rat(long a, RATIONAL b) {
long long m = (long long)a * b.m;
long long n = b.n;
simplifyRat(&m, &n);
RATIONAL x = {m, n};
return x;
return makeRATIONAL(m, n);
}

double rat2Real(RATIONAL a) {
return (double)a.m / a.n;
return (double)a.m / a.n;
}

static inline int sign(long n) {
static OMC_INLINE int sign(long n) {
return n > 0 ? 1 : -1;
}

Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/rational.h
Expand Up @@ -41,6 +41,7 @@ typedef struct RATIONAL {
long n;
} RATIONAL;

RATIONAL makeRATIONAL(long a, long b);
RATIONAL addInt2Rat(long a, RATIONAL b);
RATIONAL subInt2Rat(long a, RATIONAL b);
RATIONAL addRat2Rat(RATIONAL a, RATIONAL b);
Expand Down

0 comments on commit 68b4a60

Please sign in to comment.