Support abs as a primitive operation on floating point numbers.
Haskell differs from C and FORTRAN on the manner in which it computes the absolute value of floating point numbers. Both FORTRAN and C support a fabs primitive function that is compiled directly to the underlying fabs machine instruction on either AMD64 or Intel x86 processors (with a small amount of stack manipulation).
Haskell, however, does not support abs as a primitive operation on floating point numbers. Instead, Haskell desugars abs to the following:
abs x | x == 0 = 0 -- handles (-0.0)
| x > 0 = x
| otherwise = negateFloat x
Rather than calling the utilizing the fabs mnemonic or twiddling the sign bit, both of which can be executed in a single instruction, this implementation results in ~15 machine instructions and requires ~4-5 times the number of clock cycles to execute.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |