IEEE-754R 2008 5.3.1: nextUp/nextDown. NOTE* since nextDown(x) = -nextUp(-x), we only implement nextUp with appropriate sign switching before/after the computation.
| 3945 | /// *NOTE* since nextDown(x) = -nextUp(-x), we only implement nextUp with |
| 3946 | /// appropriate sign switching before/after the computation. |
| 3947 | IEEEFloat::opStatus IEEEFloat::next(bool nextDown) { |
| 3948 | // If we are performing nextDown, swap sign so we have -x. |
| 3949 | if (nextDown) |
| 3950 | changeSign(); |
| 3951 | |
| 3952 | // Compute nextUp(x) |
| 3953 | opStatus result = opOK; |
| 3954 | |
| 3955 | // Handle each float category separately. |
| 3956 | switch (category) { |
| 3957 | case fcInfinity: |
| 3958 | // nextUp(+inf) = +inf |
| 3959 | if (!isNegative()) |
| 3960 | break; |
| 3961 | // nextUp(-inf) = -getLargest() |
| 3962 | makeLargest(true); |
| 3963 | break; |
| 3964 | case fcNaN: |
| 3965 | // IEEE-754R 2008 6.2 Par 2: nextUp(sNaN) = qNaN. Set Invalid flag. |
| 3966 | // IEEE-754R 2008 6.2: nextUp(qNaN) = qNaN. Must be identity so we do not |
| 3967 | // change the payload. |
| 3968 | if (isSignaling()) { |
| 3969 | result = opInvalidOp; |
| 3970 | // For consistency, propagate the sign of the sNaN to the qNaN. |
| 3971 | makeNaN(false, isNegative(), nullptr); |
| 3972 | } |
| 3973 | break; |
| 3974 | case fcZero: |
| 3975 | // nextUp(pm 0) = +getSmallest() |
| 3976 | makeSmallest(false); |
| 3977 | break; |
| 3978 | case fcNormal: |
| 3979 | // nextUp(-getSmallest()) = -0 |
| 3980 | if (isSmallest() && isNegative()) { |
| 3981 | APInt::tcSet(significandParts(), 0, partCount()); |
| 3982 | category = fcZero; |
| 3983 | exponent = 0; |
| 3984 | break; |
| 3985 | } |
| 3986 | |
| 3987 | // nextUp(getLargest()) == INFINITY |
| 3988 | if (isLargest() && !isNegative()) { |
| 3989 | APInt::tcSet(significandParts(), 0, partCount()); |
| 3990 | category = fcInfinity; |
| 3991 | exponent = semantics->maxExponent + 1; |
| 3992 | break; |
| 3993 | } |
| 3994 | |
| 3995 | // nextUp(normal) == normal + inc. |
| 3996 | if (isNegative()) { |
| 3997 | // If we are negative, we need to decrement the significand. |
| 3998 | |
| 3999 | // We only cross a binade boundary that requires adjusting the exponent |
| 4000 | // if: |
| 4001 | // 1. exponent != semantics->minExponent. This implies we are not in the |
| 4002 | // smallest binade or are dealing with denormals. |
| 4003 | // 2. Our significand excluding the integral bit is all zeros. |
| 4004 | bool WillCrossBinadeBoundary = |
nothing calls this directly
no test coverage detected