2019-04-08 04:00:47 +00:00
|
|
|
|
2019-09-26 07:48:02 +00:00
|
|
|
#include "Moo.moo".
|
2019-04-08 04:00:47 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
////////////////////////////////////////////////////////////////#
|
|
|
|
// MAIN
|
|
|
|
////////////////////////////////////////////////////////////////#
|
2019-04-08 04:00:47 +00:00
|
|
|
|
|
|
|
class MyObject(Object)
|
|
|
|
{
|
|
|
|
var(#class) a := 100.
|
|
|
|
var(#classinst) K := 200.
|
|
|
|
|
|
|
|
method(#class) testBigintDiv
|
|
|
|
{
|
|
|
|
| i q r divd divr divd_ubound divr_ubound |
|
|
|
|
|
|
|
|
divr_ubound := 16rFFFFFFFFFFFFFFFFFFFFFFFF.
|
|
|
|
divd_ubound := 16rFFFFFFFFFFFFFFFFFFFFFFFF.
|
|
|
|
|
|
|
|
divr := 1.
|
|
|
|
while (divr <= divr_ubound)
|
|
|
|
{
|
2019-09-26 07:48:02 +00:00
|
|
|
("divr => " & divr asString) dump.
|
2019-04-08 04:00:47 +00:00
|
|
|
|
|
|
|
divd := 0.
|
|
|
|
while (divd <= divd_ubound)
|
|
|
|
{
|
|
|
|
q := divd div: divr.
|
|
|
|
r := divd rem: divr.
|
|
|
|
if (divd ~= (q * divr + r)) { i dump. divd dump. divr dump. q dump. r dump. (q * divr + r) dump. ^false. }.
|
|
|
|
divd := divd + 1.
|
|
|
|
}.
|
|
|
|
divd := divr + 1.
|
|
|
|
}.
|
|
|
|
^true
|
|
|
|
}
|
|
|
|
|
|
|
|
method(#class) testBigintDiv2
|
|
|
|
{
|
2019-08-24 15:45:08 +00:00
|
|
|
| ffi now |
|
2019-04-08 04:00:47 +00:00
|
|
|
|
|
|
|
|
2019-10-11 03:30:00 +00:00
|
|
|
[ ffi := FFI new: "libc.so.6". ] on: Exception do: [:ex |
|
|
|
|
[ ffi := FFI new: "libc.so" ] on: Exception do: [ :ex2 | ffi := FFI new: "msvcrt.dll" ]
|
|
|
|
].
|
2019-09-05 08:45:04 +00:00
|
|
|
|
2019-09-26 07:48:02 +00:00
|
|
|
now := ffi call: #time signature: "l>i" arguments: #(0).
|
2019-10-11 03:30:00 +00:00
|
|
|
ffi call: #srand signature: "i>" arguments: ##(now).
|
|
|
|
///ffi call: #srandom signature: "i>" arguments: ##(now).
|
2019-04-08 04:00:47 +00:00
|
|
|
|
|
|
|
[
|
2019-08-24 15:45:08 +00:00
|
|
|
| i q r divd divr divd_ubound divr_ubound x |
|
2019-09-26 07:48:02 +00:00
|
|
|
|
2019-04-08 04:00:47 +00:00
|
|
|
divr_ubound := 16rFFFFFFFFFFFFFFFFFFFFFFFF.
|
|
|
|
divd_ubound := 16rFFFFFFFFFFFFFFFFFFFFFFFF.
|
2019-08-24 15:45:08 +00:00
|
|
|
i := 0.
|
2019-04-08 04:00:47 +00:00
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2019-10-11 03:30:00 +00:00
|
|
|
x := (ffi call: #rand signature: ">i" arguments: nil) rem: 20.
|
|
|
|
divd := (ffi call: #rand signature: ">i" arguments: nil).
|
|
|
|
///x := (ffi call: #random signature: ">l" arguments: nil) rem: 20.
|
|
|
|
///divd := (ffi call: #random signature: ">l" arguments: nil).
|
2019-04-08 04:00:47 +00:00
|
|
|
while (x > 0)
|
|
|
|
{
|
2019-10-11 03:30:00 +00:00
|
|
|
divd := (divd bitShift: 7) bitOr: (ffi call: #rand signature: ">i" arguments: nil).
|
|
|
|
///divd := (divd bitShift: 7) bitOr: (ffi call: #random signature: ">l" arguments: nil).
|
2019-04-08 04:00:47 +00:00
|
|
|
x := x - 1.
|
|
|
|
}.
|
|
|
|
|
2019-10-11 03:30:00 +00:00
|
|
|
x := (ffi call: #rand signature: ">i" arguments: nil) rem: 20.
|
|
|
|
divr := (ffi call: #rand signature: ">i" arguments: nil).
|
|
|
|
///x := (ffi call: #random signature: ">l" arguments: nil) rem: 20.
|
|
|
|
///divr := (ffi call: #random signature: ">l" arguments: nil).
|
2019-04-08 04:00:47 +00:00
|
|
|
while (x > 0)
|
|
|
|
{
|
2019-10-11 03:30:00 +00:00
|
|
|
divr := (divr bitShift: 7) bitOr: (ffi call: #rand signature: ">i" arguments: nil).
|
|
|
|
//divr := (divr bitShift: 7) bitOr: (ffi call: #random signature: ">l" arguments: nil).
|
2019-04-08 04:00:47 +00:00
|
|
|
x := x - 1.
|
|
|
|
}.
|
|
|
|
if (divr = 0) { divr := 1 }.
|
|
|
|
|
2019-08-24 15:45:08 +00:00
|
|
|
i := i + 1.
|
2019-09-26 07:48:02 +00:00
|
|
|
ffi call: #printf signature: "s | l > l" arguments: ##("%d\r", i).
|
2019-08-24 15:45:08 +00:00
|
|
|
|
2019-04-08 04:00:47 +00:00
|
|
|
q := divd div: divr.
|
|
|
|
r := divd rem: divr.
|
2019-08-09 18:19:13 +00:00
|
|
|
if (divd ~= (q * divr + r))
|
|
|
|
{
|
|
|
|
// dump numbers if result is wrong
|
|
|
|
divd dump.
|
|
|
|
divr dump.
|
|
|
|
q dump.
|
|
|
|
r dump.
|
|
|
|
(q * divr + r) dump.
|
|
|
|
^false.
|
|
|
|
}.
|
2019-09-26 07:48:02 +00:00
|
|
|
////((q asString) & " " & (r asString)) dump
|
2019-04-08 04:00:47 +00:00
|
|
|
}.
|
|
|
|
] ensure: [ ffi close. ].
|
|
|
|
^true
|
|
|
|
}
|
|
|
|
|
|
|
|
method(#class) main
|
|
|
|
{
|
|
|
|
self testBigintDiv2.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|