问题
Are there any fully compliant IEEE754r implementations available for Java that offer support for all the features Java chose to omit (or rather high level languages in general like to omit):
- Traps
- Sticky flags
- Directed rounding modes
- Extended/long double
- Quad precision
- DPD (densly packed decimals)
Clarification before anyone gets it wrong: I'm not looking for the JVM to offer any support for the above, just some classes that do implement the types and operations in software, basically something in the style of the already existing primitve wrapper classes Float/Double.
回答1:
No, there does not exist a fully compliant IEEE754R implementation. Not only in Java, but in all currently available languages (Status July 2012).
EDIT: The poster asked for IEEE754 R support which is identical to IEEE 754-2008. If I want to add all reasons why there is no such thing, this would be long.
Traps: No, calling own routines with OVERFLOW, UNDERFLOW, INEXACT etc. with SIGFPE is not a trap. See IEEE754 (the old one) p. 21 for what constitutes a trap. Signaling NaNs. NaN payload access. Flag access. Enumerate languages which can do that.
Rounding modes: The new standard defines roundTiesToAway (p. 16) as new rounding mode. Unfortunately there are AFAIK no processors which supports this mode and no software emulation either.
Quad precision: Only supported in very few compilers and even less compilers which are not broken.
Densely packed Decimals: Will probably only supported in languages which use decimals, e.g. COBOL.
Intersection of all sets: Empty set. None. Nothing.
回答2:
This with the following source implemented functions below:
double nextAfter(double x, double y) - returns the double adjacent to x in the direction of y
double scalb(double x, int e) - computes x*2e quickly
boolean unordered(double c1, double c2) - returns true iff the two cannot be compared numerically (one or both is NaN)
int fpclassify(double value) - classifies a floating-point value into one of five types:
FP_NAN: "not any number", typically the result of illegal operations like 0/0
FP_INFINITY: represents one end of the real line, available by 1/0 or POSITIVE_INFINITY
FP_ZERO: positive or negative zero; they are different, but not so much that it comes up much
FP_SUBNORMAL: a class of numbers very near zero; further explanation would require a detailed examination of the floating-point binary representation
FP_NORMAL: most values you encounter are "normal"
double copySign(double value, double sign) - returns value, possibly with its sign flipped, to match "sign"
double logb754(double value) - extracts the exponent of the value, to compute log2
double logb854(double value) - like logb754(value), but with an IEEE854-compliant variant for subnormal numbers
double logbn(double value) - also computing log2(value), but with a normalizing correction for the subnormals; this is the best log routine
double raise(double x) - not actually an IEEE754 routine, this is an optimized version of nextAfter(x,POSITIVE_INFINITY)
double lower(double x) - not actually an IEEE754 routine, this is an optimized version of nextAfter(x,NEGATIVE_INFINITY)
"All of these routines also have float variants, differing only in argument and return types. The class is org.dosereality.util.IEEE754"
Sun bug reference 2003
来源:https://stackoverflow.com/questions/11474424/any-ieee754r-compliant-implementations-for-java