Design: Decimal/Money type

Created on 6 Aug 2017  路  3Comments  路  Source: WebAssembly/design

There are a lot of good WASM documents about Float type and its arithmetic with fraction part being (2-based)^(-1).

For years programmers have been using work arounds in JavaScript to achieve proper decimal fraction calculation due the only 64-bit floating type for all numerics.
Is there a plan to support __Money__ type or __Decimal__ type (Example 1, Example 2)?

Practically decimal type is important for most any business application. Many languages, platforms and databases support it.

Most helpful comment

I don't think the OP is asking for BCD support but rather for support for decimal floating point. Other than that, I agree with @jfbastien, we should be wary of supporting something that isn't frequently available in hardware. According to the Wikipedia page I cited, only IBM hardware so far implements it. ISTR there were rumors about Intel pursuing it but nothing appears to have materialized.

Intel appears to offer an emulation library which is claimed to be portable, so, presumably C that could be compiled to Wasm. I haven't looked into that at all, not even to verify that my presumption is correct.

All 3 comments

WebAssembly exposes common hardware features when these features make usecases faster. It doesn't in general expose anything else: it is expected that useful features are built using these primitives.

We'd therefore evaluate binary-coded decimal as follows:

  • Is it widely available in modern ISAs? No. It was in older x86 and isn't available in long mode.
  • Is it faster? A case could be made that sometimes, having the intent expressed (e.g. "perform BCD add") can lead to better code because intent is otherwise lost and the compiler can't get it back. That's not clearly the case here, but I'm willing to be convinced otherwise.

Note that how useful a feature is simply isn't relevant for this. If it's useful then a library can be built (or better, some C++ codebase can be compiled to WebAssembly). Usefulness and presence of a champion for the feature only factors into when we'll get to it.

I don't think the OP is asking for BCD support but rather for support for decimal floating point. Other than that, I agree with @jfbastien, we should be wary of supporting something that isn't frequently available in hardware. According to the Wikipedia page I cited, only IBM hardware so far implements it. ISTR there were rumors about Intel pursuing it but nothing appears to have materialized.

Intel appears to offer an emulation library which is claimed to be portable, so, presumably C that could be compiled to Wasm. I haven't looked into that at all, not even to verify that my presumption is correct.

Tank you @jfbastien and @lars-t-hansen for the answers.

Now it is clear that this problem is not WASM related and should be addressed to another group.

A library can solve this problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfbastien picture jfbastien  路  6Comments

mfateev picture mfateev  路  5Comments

spidoche picture spidoche  路  4Comments

konsoletyper picture konsoletyper  路  6Comments

void4 picture void4  路  5Comments