Skip to content

Commit e75d006

Browse files
committed
Implement Math/Mathf.pow
1 parent e26734e commit e75d006

18 files changed

+11718
-2644
lines changed

bin/asc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,16 @@ function measure(fn) {
765765

766766
exports.measure = measure;
767767

768+
function formatTime(time) {
769+
return time ? (time / 1e6).toFixed(3) + " ms" : "N/A";
770+
}
771+
772+
exports.formatTime = formatTime;
773+
768774
/** Formats and prints out the contents of a set of stats. */
769775
function printStats(stats, output) {
770776
function format(time, count) {
771-
return time ? (time / 1e6).toFixed(3) + " ms" : "N/A";
777+
return formatTime(time);
772778
}
773779
(output || process.stdout).write([
774780
"I/O Read : " + format(stats.readTime, stats.readCount),

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/hexfloat.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
label { cursor: pointer; }
66
</style>
77

8-
<script src="hexfloat.js"></script>
98
<form onsubmit="convert(this); return false">
109
<h1>Hexadecimal float to decimal float converter</h1>
1110
<p>
1211
<label for="f64"><input id="f64" name="precision" value="f64" type="radio" checked /> f64</label>
1312
<label for="f32"><input id="f32" name="precision" value="f32" type="radio" /> f32</label>
14-
<input id="name" type="text" value="test(" />
13+
<input id="name" type="text" value="test" />
1514
<button>Convert</button>
1615
</p>
1716
<p><textarea cols="120" rows="20" id="input"></textarea></p>
1817
<p><textarea cols="120" rows="20" id="output" readonly></textarea></p>
1918
</form>
2019

20+
<script src="hexfloat.js"></script>
2121
<script>
2222
function convert(form) {
2323
var isF64 = document.getElementById("f64").checked;
@@ -29,8 +29,8 @@ <h1>Hexadecimal float to decimal float converter</h1>
2929
return val.toPrecision(isF64 ? 18 : 10);
3030
})
3131
.replace(/\bnan\b/g, "NaN")
32-
.replace(/\inf\b/g, "Infinity")
33-
.replace(/^T\(RN, */mg, name + "(")
32+
.replace(/\binf\b/g, "Infinity")
33+
.replace(/^T\(R\w, */mg, name + "(")
3434
.replace(/\)$/mg, ");")
3535
.replace(/ +/g, " ");
3636
}

src/builtins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ export function compileCall(
19031903
}
19041904
let type = compiler.currentType;
19051905
arg1 = compiler.compileExpression(operands[1], type);
1906-
arg2 = compiler.compileExpression(operands[2], Type.bool);
1906+
arg2 = compiler.compileExpression(operands[2], Type.i32);
19071907
compiler.currentType = type;
19081908
switch (compiler.currentType.kind) {
19091909
default: { // any value type

src/compiler.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4904,24 +4904,21 @@ export class Compiler extends DiagnosticEmitter {
49044904
if (i64_is_i8(intValue)) return module.createI32(i64_low(intValue));
49054905
break;
49064906
}
4907-
case TypeKind.I16: {
4908-
if (i64_is_i16(intValue)) return module.createI32(i64_low(intValue));
4909-
break;
4910-
}
4911-
case TypeKind.I32: {
4912-
if (i64_is_i32(intValue)) return module.createI32(i64_low(intValue));
4913-
break;
4914-
}
49154907
case TypeKind.U8: {
49164908
if (i64_is_u8(intValue)) return module.createI32(i64_low(intValue));
49174909
break;
49184910
}
4911+
case TypeKind.I16: {
4912+
if (i64_is_i16(intValue)) return module.createI32(i64_low(intValue));
4913+
break;
4914+
}
49194915
case TypeKind.U16: {
49204916
if (i64_is_u16(intValue)) return module.createI32(i64_low(intValue));
49214917
break;
49224918
}
4919+
case TypeKind.I32:
49234920
case TypeKind.U32: {
4924-
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
4921+
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
49254922
break;
49264923
}
49274924
case TypeKind.BOOL: {
@@ -4930,14 +4927,14 @@ export class Compiler extends DiagnosticEmitter {
49304927
}
49314928
case TypeKind.ISIZE: {
49324929
if (!this.options.isWasm64) {
4933-
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
4930+
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
49344931
break;
49354932
}
49364933
return module.createI64(i64_low(intValue), i64_high(intValue));
49374934
}
49384935
case TypeKind.USIZE: {
49394936
if (!this.options.isWasm64) {
4940-
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
4937+
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
49414938
break;
49424939
}
49434940
return module.createI64(i64_low(intValue), i64_high(intValue));

std/assembly.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ declare namespace Math {
418418
export function log(x: f64): f64;
419419
export function max(value1: f64, value2: f64): f64; // TODO: see std/math
420420
export function min(value1: f64, value2: f64): f64; // TODO: see std/math
421+
export function pow(x: f64, y: f64): f64;
421422
export function round(x: f64): f64;
422423
export function sign(x: f64): f64;
423424
export function sqrt(x: f64): f64;
@@ -442,6 +443,7 @@ declare namespace Mathf {
442443
export function log(x: f32): f32;
443444
export function max(value1: f32, value2: f32): f32; // TODO: see std/math
444445
export function min(value1: f32, value2: f32): f32; // TODO: see std/math
446+
export function pow(x: f32, y: f32): f32;
445447
export function round(x: f32): f32;
446448
export function sign(x: f32): f32;
447449
export function sqrt(x: f32): f32;

0 commit comments

Comments
 (0)