what languages expose IEEE 754 traps to the developer?

后端 未结 4 1041
天命终不由人
天命终不由人 2021-02-14 22:38

I\'d like to play with those traps for educational purpose.

A common problem with the default behavior in numerical calculus is that we \"miss\" the Nan (or +-inf) that

4条回答
  •  伪装坚强ぢ
    2021-02-14 23:11

    Maple's programming language has a numeric model that respects IEEE-754 and allows you to set your own trap handlers, if you want. Here are some links:

    • Differences between IEEE-754 and Maple's numerics (they're pretty minor - it's mostly just names of functions)
    • General info on numeric computation in Maple
    • Info on how to obtain & set numeric event handlers (the Maple term for trap handlers)

    An uncommon property of Maple is that default floating point numbers are decimal (not binary) and of arbitrary precision. If you want to deal with 64-bit binary floating point numbers, wrap them in HFloat. For example, 0.2 represents the decimal number exactly, whereas HFloat(0.2) represents the same number you'd get by assigning 0.2 to a double in C. This is evident by running, for example,

    a := HFloat(0.2);
    b := 0.2;
    evalf[20](a - b);
    

    This computes the difference between a and b using 20 decimal digit arithmetic, and the result is 0.11E-16.

提交回复
热议问题