Skip to content

Commit d27bfb4

Browse files
committed
WyRT: Updated standard library for #418.
1 parent 0bf8c5c commit d27bfb4

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

modules/wyrt/src/whiley/lang/Int.whiley

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function parse(string input) => int
172172
r = r * 10
173173
if !Char.isDigit(c):
174174
throw SyntaxError("invalid number string",i,i)
175-
r = r + (c - '0')
175+
r = r + ((int) c - '0')
176176
// done
177177
if negative:
178178
return -r

modules/wyrt/src/whiley/lang/Math.whiley

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ ensures x < 0 ==> r == -x:
4444
*/
4545
public function abs(real x) => (real r)
4646
// if input positive, then result equals input
47-
ensures x >= 0 ==> r == x
47+
ensures x >= 0.0 ==> r == x
4848
// if input negative, then result equals negated input
49-
ensures x < 0 ==> r == -x:
49+
ensures x < 0.0 ==> r == -x:
5050
//
51-
if x < 0:
51+
if x < 0.0:
5252
return -x
5353
else:
5454
return x
@@ -127,15 +127,15 @@ requires exponent > 0:
127127
*/
128128
public function floor(real x) => (int r)
129129
// Return is greater-than-or-equal to input
130-
ensures r <= x
130+
ensures ((real) r) <= x
131131
// Input value is between return and return plus one
132-
ensures r + 1 > x:
132+
ensures ((real) r + 1) > x:
133133
//
134134
int num
135135
int den
136136
num/den = x
137137
int r = num / den
138-
if x < 0 && den != 1:
138+
if x < 0.0 && den != 1:
139139
return r - 1
140140
else:
141141
return r
@@ -146,15 +146,15 @@ ensures r + 1 > x:
146146
*/
147147
public function ceil(real x) => (int r)
148148
// Return is greater-than-or-equal to input
149-
ensures x <= r
149+
ensures x <= ((real) r)
150150
// Input value is between return and return less one
151-
ensures r - 1 < x:
151+
ensures ((real) r - 1) < x:
152152
//
153153
int num
154154
int den
155155
num/den = x
156156
int r = num / den
157-
if x > 0 && den != 1:
157+
if x > 0.0 && den != 1:
158158
return r + 1
159159
else:
160160
return r
@@ -165,9 +165,9 @@ ensures r - 1 < x:
165165
*/
166166
public function round(real x) => (int r)
167167
// Difference between input and return is 0.5 or less
168-
ensures max(x,r) - min(x,r) <= 0.5:
168+
ensures max(x,(real) r) - min(x, (real) r) <= 0.5:
169169
//
170-
if x >= 0:
170+
if x >= 0.0:
171171
return floor(x + 0.5)
172172
else:
173173
return ceil(x - 0.5)

modules/wyrt/src/whiley/lang/Real.whiley

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ throws SyntaxError:
4747
throw SyntaxError("invalid number string",i,i)
4848
else:
4949
r = r * 10
50-
r = r + (c - '0')
50+
r = r + (int) (c - '0')
5151
dps = dps * 10
5252
// finally, perform division
5353
real rr = (real) r
5454
if dps > 0:
55-
return rr / dps
55+
return rr / (real) dps
5656
else:
5757
return rr
5858

@@ -63,21 +63,21 @@ public function toDecimal(real x) => string:
6363
// the following is a convenience method.
6464
public function toDecimal(real x, int ndigits) => string:
6565
string r
66-
if x < 0:
66+
if x < 0.0:
6767
r = "-"
6868
x = -x
6969
else:
7070
r = ""
7171
int n / int d = x
7272
int digit = n / d
73-
real rem = x - digit
73+
real rem = x - (real) digit
7474
r = r ++ digit ++ "."
7575
int i = 1
76-
while i < ndigits && rem != 0:
77-
rem = rem * 10
76+
while i < ndigits && rem != 0.0:
77+
rem = rem * 10.0
7878
n / d = rem
7979
digit = n / d
80-
rem = rem - digit
80+
rem = rem - (real) digit
8181
r = r ++ digit
8282
i = i + 1
8383
// need to support rounding!

modules/wyrt/src/whiley/lang/String.whiley

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public function toUTF8(string s) => [byte]:
8383
[byte] r = []
8484
for c in s:
8585
// the following line is fatally flawed!
86-
r = r ++ [Int.toUnsignedByte(c)]
86+
r = r ++ [Int.toUnsignedByte((int) c)]
8787
return r
8888

0 commit comments

Comments
 (0)