mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 18:26:40 +00:00
decisions
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import { runtime, ArrayBufferView } from "../runtime";
|
||||
import { gc } from "../gc";
|
||||
import { ALLOCATE, REGISTER, DISCARD, ArrayBufferView } from "../runtime";
|
||||
import { CharCode } from "./string";
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@ -263,10 +262,10 @@ export function utoa32(value: u32): String {
|
||||
if (!value) return "0";
|
||||
|
||||
var decimals = decimalCount32(value);
|
||||
var out = runtime.alloc(decimals << 1);
|
||||
var out = ALLOCATE(decimals << 1);
|
||||
|
||||
utoa32_core(changetype<usize>(out), value, decimals);
|
||||
return gc.register<String>(out);
|
||||
return REGISTER<String>(out);
|
||||
}
|
||||
|
||||
export function itoa32(value: i32): String {
|
||||
@ -276,12 +275,12 @@ export function itoa32(value: i32): String {
|
||||
if (sign) value = -value;
|
||||
|
||||
var decimals = decimalCount32(value) + u32(sign);
|
||||
var out = runtime.alloc(decimals << 1);
|
||||
var out = ALLOCATE(decimals << 1);
|
||||
|
||||
utoa32_core(changetype<usize>(out), value, decimals);
|
||||
if (sign) store<u16>(changetype<usize>(out), CharCode.MINUS);
|
||||
|
||||
return gc.register<String>(out);
|
||||
return REGISTER<String>(out);
|
||||
}
|
||||
|
||||
export function utoa64(value: u64): String {
|
||||
@ -291,14 +290,14 @@ export function utoa64(value: u64): String {
|
||||
if (value <= u32.MAX_VALUE) {
|
||||
let val32 = <u32>value;
|
||||
let decimals = decimalCount32(val32);
|
||||
out = runtime.alloc(decimals << 1);
|
||||
out = ALLOCATE(decimals << 1);
|
||||
utoa32_core(out, val32, decimals);
|
||||
} else {
|
||||
let decimals = decimalCount64(value);
|
||||
out = runtime.alloc(decimals << 1);
|
||||
out = ALLOCATE(decimals << 1);
|
||||
utoa64_core(changetype<usize>(out), value, decimals);
|
||||
}
|
||||
return gc.register<String>(out);
|
||||
return REGISTER<String>(out);
|
||||
}
|
||||
|
||||
export function itoa64(value: i64): String {
|
||||
@ -311,16 +310,16 @@ export function itoa64(value: i64): String {
|
||||
if (<u64>value <= <u64>u32.MAX_VALUE) {
|
||||
let val32 = <u32>value;
|
||||
let decimals = decimalCount32(val32) + u32(sign);
|
||||
out = runtime.alloc(decimals << 1);
|
||||
out = ALLOCATE(decimals << 1);
|
||||
utoa32_core(changetype<usize>(out), val32, decimals);
|
||||
} else {
|
||||
let decimals = decimalCount64(value) + u32(sign);
|
||||
out = runtime.alloc(decimals << 1);
|
||||
out = ALLOCATE(decimals << 1);
|
||||
utoa64_core(changetype<usize>(out), value, decimals);
|
||||
}
|
||||
if (sign) store<u16>(changetype<usize>(out), CharCode.MINUS);
|
||||
|
||||
return gc.register<String>(out);
|
||||
return REGISTER<String>(out);
|
||||
}
|
||||
|
||||
export function itoa<T extends number>(value: T): String {
|
||||
@ -625,10 +624,10 @@ export function dtoa(value: f64): String {
|
||||
if (isNaN(value)) return "NaN";
|
||||
return select<String>("-Infinity", "Infinity", value < 0);
|
||||
}
|
||||
var temp = runtime.alloc(MAX_DOUBLE_LENGTH << 1);
|
||||
var temp = ALLOCATE(MAX_DOUBLE_LENGTH << 1);
|
||||
var length = dtoa_core(temp, value);
|
||||
var result = changetype<String>(temp).substring(0, length);
|
||||
runtime.freeUnregistered(temp);
|
||||
DISCARD(temp);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user