From 625213aa15f0c8224cc52ee0036fae28de0bd413 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 2 Dec 2020 14:48:38 -0700 Subject: [PATCH] No more trying to force truncation of int division --- src/kiss/Operand.hx | 22 +++++-------- src/kiss/Prelude.hx | 55 ++++++++++--------------------- src/test/cases/BasicTestCase.hx | 3 +- src/test/cases/BasicTestCase.kiss | 5 ++- 4 files changed, 30 insertions(+), 55 deletions(-) diff --git a/src/kiss/Operand.hx b/src/kiss/Operand.hx index 69b93c57..beff5fe9 100644 --- a/src/kiss/Operand.hx +++ b/src/kiss/Operand.hx @@ -5,17 +5,17 @@ import haxe.ds.Either; /** Arithmetic operands **/ -abstract Operand(Either>) from Either> to Either> { +abstract Operand(Either) from Either to Either { @:from inline static function fromString(s:String):Operand { return Left(s); } - @:from inline static function fromInt(f:Int):Operand { - return Right(Left(f)); + @:from inline static function fromInt(i:Int):Operand { + return Right(0.0 + i); } @:from inline static function fromFloat(f:Float):Operand { - return Right(Right(f)); + return Right(f); } // Doing this one implicitly just wasn't working in conjunction with Lambda.fold @@ -23,8 +23,7 @@ abstract Operand(Either>) from Either>) from Either>) from Either { return switch (this) { - case Right(Right(f)): f; - case Right(Left(i)): i; + case Right(f): f; default: null; }; } @:to public inline function toInt():Null { return switch (this) { - case Right(Left(i)): i; - case Right(Right(f)): Math.floor(f); + case Right(f): Math.floor(f); default: null; }; } @@ -69,8 +66,7 @@ abstract Operand(Either>) from Either(a:Array, size, keepRemainder = false) { diff --git a/src/test/cases/BasicTestCase.hx b/src/test/cases/BasicTestCase.hx index f104f824..6271bf0f 100644 --- a/src/test/cases/BasicTestCase.hx +++ b/src/test/cases/BasicTestCase.hx @@ -63,8 +63,7 @@ class BasicTestCase extends Test { } function testVariadicDivide() { - Assert.equals(0, BasicTestCase.myQuotientInt); - Assert.equals(0.5, BasicTestCase.myQuotientFloat); + Assert.equals(0.5, BasicTestCase.myQuotient); } function testMod() { diff --git a/src/test/cases/BasicTestCase.kiss b/src/test/cases/BasicTestCase.kiss index 1247fb72..990a8900 100644 --- a/src/test/cases/BasicTestCase.kiss +++ b/src/test/cases/BasicTestCase.kiss @@ -31,9 +31,8 @@ (defvar myProduct (* 2 5 6)) -(defvar myQuotientInt (/ 6 3 2 2)) - -(defvar myQuotientFloat (/ 6 3 2 2.0)) +// All math operations return floats, none truncate by default +(defvar myQuotient (/ 6 3 2 2)) (defvar myRemainder (% 10 6))