diff --git a/modules/wyrt/src/whiley/lang/Int.whiley b/modules/wyrt/src/whiley/lang/Int.whiley index 6e6a03c97e..49a4e8b98d 100755 --- a/modules/wyrt/src/whiley/lang/Int.whiley +++ b/modules/wyrt/src/whiley/lang/Int.whiley @@ -172,7 +172,7 @@ public function parse(string input) => int r = r * 10 if !Char.isDigit(c): throw SyntaxError("invalid number string",i,i) - r = r + (c - '0') + r = r + ((int) c - '0') // done if negative: return -r diff --git a/modules/wyrt/src/whiley/lang/Math.whiley b/modules/wyrt/src/whiley/lang/Math.whiley index 6627fa33fc..235a455d7f 100755 --- a/modules/wyrt/src/whiley/lang/Math.whiley +++ b/modules/wyrt/src/whiley/lang/Math.whiley @@ -44,11 +44,11 @@ ensures x < 0 ==> r == -x: */ public function abs(real x) => (real r) // if input positive, then result equals input -ensures x >= 0 ==> r == x +ensures x >= 0.0 ==> r == x // if input negative, then result equals negated input -ensures x < 0 ==> r == -x: +ensures x < 0.0 ==> r == -x: // - if x < 0: + if x < 0.0: return -x else: return x @@ -127,15 +127,15 @@ requires exponent > 0: */ public function floor(real x) => (int r) // Return is greater-than-or-equal to input -ensures r <= x +ensures ((real) r) <= x // Input value is between return and return plus one -ensures r + 1 > x: +ensures ((real) r + 1) > x: // int num int den num/den = x int r = num / den - if x < 0 && den != 1: + if x < 0.0 && den != 1: return r - 1 else: return r @@ -146,15 +146,15 @@ ensures r + 1 > x: */ public function ceil(real x) => (int r) // Return is greater-than-or-equal to input -ensures x <= r +ensures x <= ((real) r) // Input value is between return and return less one -ensures r - 1 < x: +ensures ((real) r - 1) < x: // int num int den num/den = x int r = num / den - if x > 0 && den != 1: + if x > 0.0 && den != 1: return r + 1 else: return r @@ -165,9 +165,9 @@ ensures r - 1 < x: */ public function round(real x) => (int r) // Difference between input and return is 0.5 or less -ensures max(x,r) - min(x,r) <= 0.5: +ensures max(x,(real) r) - min(x, (real) r) <= 0.5: // - if x >= 0: + if x >= 0.0: return floor(x + 0.5) else: return ceil(x - 0.5) diff --git a/modules/wyrt/src/whiley/lang/Real.whiley b/modules/wyrt/src/whiley/lang/Real.whiley index 9cd9be55e5..aca7afb96c 100755 --- a/modules/wyrt/src/whiley/lang/Real.whiley +++ b/modules/wyrt/src/whiley/lang/Real.whiley @@ -47,12 +47,12 @@ throws SyntaxError: throw SyntaxError("invalid number string",i,i) else: r = r * 10 - r = r + (c - '0') + r = r + (int) (c - '0') dps = dps * 10 // finally, perform division real rr = (real) r if dps > 0: - return rr / dps + return rr / (real) dps else: return rr @@ -63,21 +63,21 @@ public function toDecimal(real x) => string: // the following is a convenience method. public function toDecimal(real x, int ndigits) => string: string r - if x < 0: + if x < 0.0: r = "-" x = -x else: r = "" int n / int d = x int digit = n / d - real rem = x - digit + real rem = x - (real) digit r = r ++ digit ++ "." int i = 1 - while i < ndigits && rem != 0: - rem = rem * 10 + while i < ndigits && rem != 0.0: + rem = rem * 10.0 n / d = rem digit = n / d - rem = rem - digit + rem = rem - (real) digit r = r ++ digit i = i + 1 // need to support rounding! diff --git a/modules/wyrt/src/whiley/lang/String.whiley b/modules/wyrt/src/whiley/lang/String.whiley index 79263e82d9..85c0cf746b 100755 --- a/modules/wyrt/src/whiley/lang/String.whiley +++ b/modules/wyrt/src/whiley/lang/String.whiley @@ -83,6 +83,6 @@ public function toUTF8(string s) => [byte]: [byte] r = [] for c in s: // the following line is fatally flawed! - r = r ++ [Int.toUnsignedByte(c)] + r = r ++ [Int.toUnsignedByte((int) c)] return r