mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
wasm: fix Num.isFinite for Dec
When I wrote this code I thought it was the base10 floating point format, but in fact it's fixed-point.
This commit is contained in:
parent
19c02aa087
commit
0910831f59
1 changed files with 6 additions and 11 deletions
|
@ -870,7 +870,8 @@ fn num_is_finite(backend: &mut WasmBackend<'_>, argument: Symbol) {
|
||||||
.storage
|
.storage
|
||||||
.load_symbols(&mut backend.code_builder, &[argument]);
|
.load_symbols(&mut backend.code_builder, &[argument]);
|
||||||
match value_type {
|
match value_type {
|
||||||
ValueType::I32 | ValueType::I64 => backend.code_builder.i32_const(1), // always true for integers
|
// Integers are always finite. Just return True.
|
||||||
|
ValueType::I32 | ValueType::I64 => backend.code_builder.i32_const(1),
|
||||||
ValueType::F32 => {
|
ValueType::F32 => {
|
||||||
backend.code_builder.i32_reinterpret_f32();
|
backend.code_builder.i32_reinterpret_f32();
|
||||||
backend.code_builder.i32_const(0x7f80_0000);
|
backend.code_builder.i32_const(0x7f80_0000);
|
||||||
|
@ -893,7 +894,10 @@ fn num_is_finite(backend: &mut WasmBackend<'_>, argument: Symbol) {
|
||||||
let (local_id, offset) = location.local_and_offset(backend.storage.stack_frame_pointer);
|
let (local_id, offset) = location.local_and_offset(backend.storage.stack_frame_pointer);
|
||||||
|
|
||||||
match format {
|
match format {
|
||||||
StackMemoryFormat::Int128 => backend.code_builder.i32_const(1),
|
// Integers and fixed-point numbers are always finite. Just return True.
|
||||||
|
StackMemoryFormat::Int128 | StackMemoryFormat::Decimal => {
|
||||||
|
backend.code_builder.i32_const(1)
|
||||||
|
}
|
||||||
|
|
||||||
// f128 is not supported anywhere else but it's easy to support it here, so why not...
|
// f128 is not supported anywhere else but it's easy to support it here, so why not...
|
||||||
StackMemoryFormat::Float128 => {
|
StackMemoryFormat::Float128 => {
|
||||||
|
@ -905,15 +909,6 @@ fn num_is_finite(backend: &mut WasmBackend<'_>, argument: Symbol) {
|
||||||
backend.code_builder.i64_ne();
|
backend.code_builder.i64_ne();
|
||||||
}
|
}
|
||||||
|
|
||||||
StackMemoryFormat::Decimal => {
|
|
||||||
backend.code_builder.get_local(local_id);
|
|
||||||
backend.code_builder.i64_load(Align::Bytes4, offset + 8);
|
|
||||||
backend.code_builder.i64_const(0x7100_0000_0000_0000);
|
|
||||||
backend.code_builder.i64_and();
|
|
||||||
backend.code_builder.i64_const(0x7100_0000_0000_0000);
|
|
||||||
backend.code_builder.i64_ne();
|
|
||||||
}
|
|
||||||
|
|
||||||
StackMemoryFormat::DataStructure => {
|
StackMemoryFormat::DataStructure => {
|
||||||
internal_error!("Tried to perform NumIsFinite on a data structure")
|
internal_error!("Tried to perform NumIsFinite on a data structure")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue