-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add long integer support in native and byte code
- Loading branch information
1 parent
3d9302c
commit 30becb5
Showing
19 changed files
with
1,935 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include <assert.h> | ||
|
||
void testmuli(long a, long b, long ab) | ||
{ | ||
assert (a * b == ab); | ||
} | ||
|
||
void testdivi(long a, long b, long ab) | ||
{ | ||
assert (a / b == ab); | ||
} | ||
|
||
void shltesti(long a, long b, long ab) | ||
{ | ||
assert (a << b == ab); | ||
} | ||
|
||
void shrtesti(long a, long b, long ab) | ||
{ | ||
assert (a >> b == ab); | ||
} | ||
|
||
long sieve(long size) | ||
{ | ||
bool sieve[1000]; | ||
|
||
for(long i=0; i<size; i+=2) | ||
{ | ||
sieve[i] = false; | ||
sieve[i+1] = true; | ||
} | ||
sieve[2] = true; | ||
|
||
for (long i = 3; i * i < size;) | ||
{ | ||
long j = i * i; | ||
while (j < size) | ||
{ | ||
sieve[j] = false; | ||
j += 2 * i; | ||
} | ||
do {i++;} while (i < size && !sieve[i]); | ||
} | ||
|
||
long num = 0; | ||
for(long i=0; i<size; i++) | ||
{ | ||
if (sieve[i]) | ||
num++; | ||
} | ||
|
||
return num; | ||
} | ||
|
||
int main(void) | ||
{ | ||
|
||
testmuli(0, 0, 0); | ||
testmuli(1, 0, 0); | ||
testmuli(0, 1, 0); | ||
|
||
testmuli( 1, 1, 1); | ||
testmuli(-1, 1, -1); | ||
testmuli(-1, -1, 1); | ||
testmuli( 1, -1, -1); | ||
|
||
testmuli(5, 5, 25); | ||
testmuli( 127, 255, 32385); | ||
testmuli(-127, 255, -32385); | ||
testmuli( 127, -255, -32385); | ||
testmuli(-127, -255, 32385); | ||
|
||
testdivi( 1, 1, 1); | ||
testdivi(-1, 1, -1); | ||
testdivi( 1, -1, -1); | ||
testdivi(-1, -1, 1); | ||
|
||
testdivi( 11, 4, 2); | ||
testdivi(-11, 4, -2); | ||
testdivi( 11, -4, -2); | ||
testdivi(-11, -4, 2); | ||
|
||
shltesti( 17, 1, 34); | ||
shltesti(-17, 1, -34); | ||
shltesti( 1700, 1, 3400); | ||
shltesti(-1700, 1, -3400); | ||
|
||
shrtesti( 34, 1, 17); | ||
shrtesti(-34, 1, -17); | ||
shrtesti( 3400, 1, 1700); | ||
shrtesti(-3400, 1, -1700); | ||
|
||
shrtesti( -1, 15, -1); | ||
shrtesti(32767, 15, 0); | ||
shrtesti( -1, 14, -1); | ||
shrtesti(32767, 14, 1); | ||
|
||
shltesti( -1, 14, -16384); | ||
shltesti( 1, 14, 16384); | ||
|
||
assert(sieve(200) == 47); | ||
assert(sieve(1000) == 169); | ||
|
||
long a = 0, b = 0; | ||
for(long i=0; i<10000; i++) | ||
{ | ||
assert( 177 * i == a); | ||
assert(-177 * i == b); | ||
a += 177; | ||
b -= 177; | ||
} | ||
|
||
long c = 0, d = 0; | ||
for(long i=0; i<177; i++) | ||
{ | ||
assert( 10000 * i == c); | ||
assert(-10000 * i == d); | ||
c += 10000; | ||
d -= 10000; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.