Fix comparing result

master
kolaente 5 years ago
parent e33a33d4a4
commit 8bfcbec08a
Signed by: kolaente
GPG Key ID: F40E70337AB24C9B
  1. 26
      hal_test.go

@ -158,13 +158,6 @@ func TestNewton2(t *testing.T) {
"22 SUBNUM 3", // (8x⁶ + 3x²) - 3
"23 STORE 15", // Result in reg 15
// This is our exit condition:
// We compare the current result with the last calculated result, if both are equal, we exit
"24 SUB 50", // 50 contains the last result
"25 JUMPNULL 45", // If both are equal, we exit
"26 LOAD 15", // Otherwise load reg 15 again, store it as the current last result and continue
"27 STORE 50",
// f'(x)
"30 LOAD 20", // x⁵ which we saved earlier while calculating x⁶
"31 MULNUM 48", // x⁵ * 48
@ -179,11 +172,22 @@ func TestNewton2(t *testing.T) {
"41 DIV 25", // f(x) / f'(x)
"42 MULNUM -1", // Invert the result
"43 ADD 10", // Add x: Because we inverted the result before, we can do this instead of SUB - lets us reuse the content of the accumulator
"44 JUMP 03", // Go to the beginning
"45 LOAD 10", // Load the result
"46 OUT 1", // Print t
"47 STOP",
"44 STORE 35", // Reg 35 now contains the end result of x - f(x) / f'(x)
// This is our exit condition:
// We compare the current result with the last calculated result, if both are equal, we exit
"50 SUB 50", // Reg 50 contains the last result
"51 JUMPNULL 60", // If both are equal, we exit
"52 LOAD 35", // Otherwise load reg 15 again, store it as the current last result and continue
"53 STORE 50",
// Go to the beginning
"54 JUMP 03",
"60 LOAD 10", // Load the result
"61 OUT 1", // Print it
"62 STOP",
}
program, err := parser.ParseProgram(input)

Loading…
Cancel
Save