# Copyright 2005 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ #!/usr/bin/env rune ? def test1(x, y) :void { > def fquot := x // y > def mod := x %% y > println(`$x // $y = $fquot`) > println(`$x %% $y = $mod`) > println(`$fquot * $y + $mod = ${fquot * y + mod} vs $x`) > > def rquot := x.truncDivide(y) > def rem := x % y > println(`$x.truncDivide($y) = $rquot`) > println(`$x % $y = $rem`) > println(`$rquot * $y + $rem = ${rquot * y + rem} vs $x`) > println() > } # value: ? def test4(x, y) :void { > test1(x, y) > test1(x, -y) > test1(-x, y) > test1(-x, -y) > } # value: ? test4(5, 3) # stdout: 5 // 3 = 1 # 5 %% 3 = 2 # 1 * 3 + 2 = 5 vs 5 # 5.truncDivide(3) = 1 # 5 % 3 = 2 # 1 * 3 + 2 = 5 vs 5 # # 5 // -3 = -2 # 5 %% -3 = -1 # -2 * -3 + -1 = 5 vs 5 # 5.truncDivide(-3) = -1 # 5 % -3 = 2 # -1 * -3 + 2 = 5 vs 5 # # -5 // 3 = -2 # -5 %% 3 = 1 # -2 * 3 + 1 = -5 vs -5 # -5.truncDivide(3) = -1 # -5 % 3 = -2 # -1 * 3 + -2 = -5 vs -5 # # -5 // -3 = 1 # -5 %% -3 = -2 # 1 * -3 + -2 = -5 vs -5 # -5.truncDivide(-3) = 1 # -5 % -3 = -2 # 1 * -3 + -2 = -5 vs -5 # # ? test4(5000000000000, 3000000000000) # stdout: 5000000000000 // 3000000000000 = 1 # 5000000000000 %% 3000000000000 = 2000000000000 # 1 * 3000000000000 + 2000000000000 = 5000000000000 vs 5000000000000 # 5000000000000.truncDivide(3000000000000) = 1 # 5000000000000 % 3000000000000 = 2000000000000 # 1 * 3000000000000 + 2000000000000 = 5000000000000 vs 5000000000000 # # 5000000000000 // -3000000000000 = -2 # 5000000000000 %% -3000000000000 = -1000000000000 # -2 * -3000000000000 + -1000000000000 = 5000000000000 vs 5000000000000 # 5000000000000.truncDivide(-3000000000000) = -1 # 5000000000000 % -3000000000000 = 2000000000000 # -1 * -3000000000000 + 2000000000000 = 5000000000000 vs 5000000000000 # # -5000000000000 // 3000000000000 = -2 # -5000000000000 %% 3000000000000 = 1000000000000 # -2 * 3000000000000 + 1000000000000 = -5000000000000 vs -5000000000000 # -5000000000000.truncDivide(3000000000000) = -1 # -5000000000000 % 3000000000000 = -2000000000000 # -1 * 3000000000000 + -2000000000000 = -5000000000000 vs -5000000000000 # # -5000000000000 // -3000000000000 = 1 # -5000000000000 %% -3000000000000 = -2000000000000 # 1 * -3000000000000 + -2000000000000 = -5000000000000 vs -5000000000000 # -5000000000000.truncDivide(-3000000000000) = 1 # -5000000000000 % -3000000000000 = -2000000000000 # 1 * -3000000000000 + -2000000000000 = -5000000000000 vs -5000000000000 # # ? test4(5.0, 3.0) # stdout: 5.0 // 3.0 = 1 # 5.0 %% 3.0 = 2.0 # 1 * 3.0 + 2.0 = 5.0 vs 5.0 # 5.0.truncDivide(3.0) = 1 # 5.0 % 3.0 = 2.0 # 1 * 3.0 + 2.0 = 5.0 vs 5.0 # # 5.0 // -3.0 = -2 # 5.0 %% -3.0 = -1.0 # -2 * -3.0 + -1.0 = 5.0 vs 5.0 # 5.0.truncDivide(-3.0) = -1 # 5.0 % -3.0 = 2.0 # -1 * -3.0 + 2.0 = 5.0 vs 5.0 # # -5.0 // 3.0 = -2 # -5.0 %% 3.0 = 1.0 # -2 * 3.0 + 1.0 = -5.0 vs -5.0 # -5.0.truncDivide(3.0) = -1 # -5.0 % 3.0 = -2.0 # -1 * 3.0 + -2.0 = -5.0 vs -5.0 # # -5.0 // -3.0 = 1 # -5.0 %% -3.0 = -2.0 # 1 * -3.0 + -2.0 = -5.0 vs -5.0 # -5.0.truncDivide(-3.0) = 1 # -5.0 % -3.0 = -2.0 # 1 * -3.0 + -2.0 = -5.0 vs -5.0 # #