Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding 'deci' type #12

Open
vpisarev opened this issue Nov 9, 2021 · 0 comments
Open

adding 'deci' type #12

vpisarev opened this issue Nov 9, 2021 · 0 comments

Comments

@vpisarev
Copy link
Owner

vpisarev commented Nov 9, 2021

this is not a high-priority item at all, but maybe it would be nice to add a true 'decimal' floating-point number type to ficus, based on https://github.com/vpisarev/DEC64/tree/alt.

The rationale:

  1. since it's purely software implementation that does not use floating-point operations internally, the operations on deci are guaranteed to give absolutely the same 'bit-exact' results on every platform, which can be useful for some accuracy-critical algorithms, reference implementations in tests etc.
  2. for quite a broad range of values scanning/printing operations are 'bit-exact', i.e. the textual decimal representation of floating-point numbers perfectly matches the internal representation, unlike with IEEE754 binary-2 numbers.
  3. the number of bits in deci's mantissa is greater than in double-precision IEEE754 format, hence the better accuracy can be achieved out-of-the-box. Besides, some extra primitives, such a super-accurate dot-product or Horner scheme (polynomial evaluation) can be added to the runtime to obtain even better accuracy (for IEEE754 formats such functions are possible and useful to implement as well though)

The details:

  1. the type may be called 'deci', short for 'decimal'.
  2. there should be 'd'/'D' suffix to specify literals of 'deci' type.
  3. basic and not so basic operations on deci() (+, -, *, /, fmod, pow, sqrt, sin, cos, exp, log, etc.) will be added to ficus runtime and the standard library. Note: the current implementation partly uses __int128 type, which is GCC/clang extension. Need to add a branch for MSVC (the necessary multiply/divide intrinsics exist in MSVC).
  4. operations on the type are converted to runtime calls at the C code generation phase.
  5. some compile-time optimizations (e.g. constant folding, a+0, a*1 etc.) maybe applied to 'deci' operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant