Skip to content

Commit

Permalink
Merge pull request #128 from donc/denormalized
Browse files Browse the repository at this point in the history
Pull 62 from jkm: Add denormalizedException for floating point
Does not include the precision control functions which were also in pull 62.
  • Loading branch information
Don Clugston committed Jun 30, 2011
2 parents 4496f58 + e3c1185 commit 37c9b2a
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions std/math.d
Expand Up @@ -1355,7 +1355,7 @@ unittest
for (int i=0; i<exptestpoints.length;++i) {
resetIeeeFlags();
x = exp(exptestpoints[i][0]);
f = ieeeFlags();
f = ieeeFlags;
assert(x == exptestpoints[i][1]);
// Check the overflow bit
assert(f.overflow() == (fabs(x) == real.infinity));
Expand All @@ -1373,7 +1373,7 @@ unittest
// NaN propagation. Doesn't set flags, bcos was already NaN.
resetIeeeFlags();
x = exp(real.nan);
f = ieeeFlags();
f = ieeeFlags;
assert(isIdentical(x,real.nan));
assert(f.flags == 0);

Expand Down Expand Up @@ -2217,23 +2217,23 @@ private:
public:
/// The result cannot be represented exactly, so rounding occured.
/// (example: x = sin(0.1); )
bool inexact() { return (flags & INEXACT_MASK) != 0; }
@property bool inexact() { return (flags & INEXACT_MASK) != 0; }
/// A zero was generated by underflow (example: x = real.min*real.epsilon/2;)
bool underflow() { return (flags & UNDERFLOW_MASK) != 0; }
@property bool underflow() { return (flags & UNDERFLOW_MASK) != 0; }
/// An infinity was generated by overflow (example: x = real.max*2;)
bool overflow() { return (flags & OVERFLOW_MASK) != 0; }
@property bool overflow() { return (flags & OVERFLOW_MASK) != 0; }
/// An infinity was generated by division by zero (example: x = 3/0.0; )
bool divByZero() { return (flags & DIVBYZERO_MASK) != 0; }
@property bool divByZero() { return (flags & DIVBYZERO_MASK) != 0; }
/// A machine NaN was generated. (example: x = real.infinity * 0.0; )
bool invalid() { return (flags & INVALID_MASK) != 0; }
@property bool invalid() { return (flags & INVALID_MASK) != 0; }
}


/// Set all of the floating-point status flags to false.
void resetIeeeFlags() { IeeeFlags.resetIeeeFlags; }

/// Return a snapshot of the current state of the floating-point status flags.
IeeeFlags ieeeFlags()
@property IeeeFlags ieeeFlags()
{
return IeeeFlags(IeeeFlags.getIeeeFlags());
}
Expand Down Expand Up @@ -2293,16 +2293,17 @@ struct FloatingPointControl
*/
enum : uint
{
inexactException = 0x20,
underflowException = 0x10,
overflowException = 0x08,
divByZeroException = 0x04,
invalidException = 0x01,
inexactException = 0x20,
underflowException = 0x10,
overflowException = 0x08,
divByZeroException = 0x04,
denormalizedException = 0x02,
invalidException = 0x01,
/// Severe = The overflow, division by zero, and invalid exceptions.
severeExceptions = overflowException | divByZeroException
| invalidException,
allExceptions = severeExceptions | underflowException
| inexactException,
| inexactException | denormalizedException,
};
private:
enum ushort EXCEPTION_MASK = 0x3F;
Expand All @@ -2321,18 +2322,18 @@ public:
setControlState(getControlState() | (exceptions & EXCEPTION_MASK));
}
//// Change the floating-point hardware rounding mode
void rounding(RoundingMode newMode)
@property void rounding(RoundingMode newMode)
{
ushort old = getControlState();
setControlState((old & ~ROUNDING_MASK) | (newMode & ROUNDING_MASK));
}
/// Return the exceptions which are currently enabled (unmasked)
static uint enabledExceptions()
@property static uint enabledExceptions()
{
return (getControlState() & EXCEPTION_MASK) ^ EXCEPTION_MASK;
}
/// Return the currently active rounding mode
static RoundingMode rounding()
@property static RoundingMode rounding()
{
return cast(RoundingMode)(getControlState() & ROUNDING_MASK);
}
Expand Down

0 comments on commit 37c9b2a

Please sign in to comment.