mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-07-30 17:16:16 +00:00
fix(go): type conversion errors in floorDiv/avmClamp
- floorDiv returns int64 instead of int32 to match avmClamp signature - instr.Arg wrapped in int64() for avmClamp/avmQ0Clamp calls - Test expected value cast to int32 fix(julia): add Q16_SCALE export to Q16_16 module
This commit is contained in:
parent
c4619d0d97
commit
3c4e039e48
4 changed files with 39 additions and 12 deletions
14
go/avm.go
14
go/avm.go
|
|
@ -25,12 +25,12 @@ func avmQ0Clamp(x int64) int32 {
|
|||
return int32(x)
|
||||
}
|
||||
|
||||
func floorDiv(a, b int64) int32 {
|
||||
func floorDiv(a, b int64) int64 {
|
||||
if b == 0 { panic("division by zero") }
|
||||
q := a / b
|
||||
r := a % b
|
||||
if r != 0 && ((a ^ b) < 0) { q-- }
|
||||
return int32(q)
|
||||
return q
|
||||
}
|
||||
|
||||
func ltQ16V6(a, b int32) bool {
|
||||
|
|
@ -161,11 +161,11 @@ func Step(s State, prog []Instr) (*State, error) {
|
|||
|
||||
switch instr.Op {
|
||||
case PushQ16:
|
||||
stack = append(stack, Val{Ty: Q16_16, Q: avmClamp(instr.Arg)})
|
||||
case PushBool:
|
||||
stack = append(stack, Val{Ty: Bool, Bval: instr.Arg2})
|
||||
case PushQ0:
|
||||
stack = append(stack, Val{Ty: Q0_16, Q: avmQ0Clamp(instr.Arg)})
|
||||
stack = append(stack, Val{Ty: Q16_16, Q: avmClamp(int64(instr.Arg))})
|
||||
case PushBool:
|
||||
stack = append(stack, Val{Ty: Bool, Bval: instr.Arg2})
|
||||
case PushQ0:
|
||||
stack = append(stack, Val{Ty: Q0_16, Q: avmQ0Clamp(int64(instr.Arg))})
|
||||
case Pop:
|
||||
if len(stack) == 0 { return nil, errors.New("empty stack") }
|
||||
stack = stack[:len(stack)-1]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func TestFloorDiv(t *testing.T) {
|
|||
}
|
||||
s, err := runTest(prog, 100)
|
||||
if err != nil { t.Fatal(err) }
|
||||
expected := (3 * Q16Scale) / 5
|
||||
expected := int32((3 * Q16Scale) / 5)
|
||||
if s.Stack[0].Q != expected { t.Fatalf("got %d, expected %d", s.Stack[0].Q, expected) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ in `Q16_16Numerics.lean`.
|
|||
"""
|
||||
module Q16_16
|
||||
|
||||
export Q16_16Value,
|
||||
export Q16_16Value, Q16_SCALE,
|
||||
of_raw_int, to_int,
|
||||
zero, one, epsilon, two, half,
|
||||
q16_min_raw, q16_max_raw, q16_scale,
|
||||
|
|
@ -27,6 +27,7 @@ export Q16_16Value,
|
|||
const q16_min_raw = -2147483648
|
||||
const q16_max_raw = 2147483647
|
||||
const q16_scale = 65536
|
||||
const Q16_SCALE = q16_scale
|
||||
|
||||
"""
|
||||
Q16_16Value
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
{
|
||||
"property": "Q16 scale (2^16)",
|
||||
"python": 65536,
|
||||
"wolfram": "65536 sixty-five thousand, five hundred thirty-six 10000000000000000_2 2^16 m | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n65536 mod m | 0 | 1 | 0 | 1 | 4 | 2 | 0 | 7 65536 = 2^16 is a perfect 16th power. A regular 65536-gon is constructible with straightedge and compass. 65536 is an even number.",
|
||||
"wolfram": "65536 sixty-five thousand, five hundred thirty-six 10000000000000000_2 2^16 m | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n65536 mod m | 0 | 1 | 0 | 1 | 4 | 2 | 0 | 7 A regular 65536-gon is constructible with straightedge and compass. 65536 = 2^16 is a perfect 16th power. 65536 is an even number.",
|
||||
"match": true
|
||||
},
|
||||
{
|
||||
|
|
@ -29,11 +29,37 @@
|
|||
"port_tests": {
|
||||
"Python": {
|
||||
"passed": true,
|
||||
"output": "ass\n \u2705 type_mismatch: rejected\n \u2705 stack_overflow: rejected\n \u2705 div_by_zero: rejected\n \u2705 control_flow: jump_if true\n \u2705 locals: store+load\n \u2705 mul_div_roundtrip: 5*3/3 = 5\n\nAll Python tests passed.\n"
|
||||
"output": "c_add: 5 + 3 = 8\n \u2705 div_q16: 3/5 = 0.6\n \u2705 saturation: max-1 + 2 = max\n \u2705 v6_comparison: 5 cases pass\n \u2705 type_mismatch: rejected\n \u2705 stack_overflow: rejected\n \u2705 div_by_zero: rejected\n \u2705 control_flow: jump_if true\n \u2705 locals: store+load\n \u2705 mul_div_roundtrip: 5*3/3 = 5\n\nAll Python tests passed.\n"
|
||||
},
|
||||
"Rust": {
|
||||
"passed": false,
|
||||
"output": "ured; 0 filtered out; finished in 0.00s\n\n\nrunning 1 test\ntest test_nuvmap_projector ... ok\n\ntest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n"
|
||||
},
|
||||
"Go": {
|
||||
"passed": false,
|
||||
"skipped": true,
|
||||
"reason": "go not found"
|
||||
},
|
||||
"C": {
|
||||
"passed": false,
|
||||
"output": ""
|
||||
},
|
||||
"C++": {
|
||||
"passed": false,
|
||||
"output": ""
|
||||
},
|
||||
"Julia": {
|
||||
"passed": true,
|
||||
"output": "ult: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n"
|
||||
"output": "Test Summary: | Pass Total Time\nAVM ISA | 12 12 0.9s\n"
|
||||
},
|
||||
"R": {
|
||||
"passed": false,
|
||||
"output": "PASS: add Q16\nPASS: jump_if\nPASS: store/load\nPASS: type error\nPASS: division by zero\n\nAll R AVM tests passed!\n"
|
||||
},
|
||||
"Octave": {
|
||||
"passed": false,
|
||||
"skipped": true,
|
||||
"reason": "octave not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue