public static ULong Remainder(ULong lowDividend, ULong highDividend, ULong divisor) { unchecked { ULong t = highDividend % divisor; return(MathEx.BigRemInternal(lowDividend, t, divisor)); } }
// 109 Cyc (special inpot set test6) public static ULong Remainder(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong highResult) { unchecked { if (0u != highDivisor) { if (0 <= (Long)highDivisor) { ULong lowProduct; ULong highProduct; ULong lowResult; ULong t; { var cc = 0; // CountLeadingZeros // ? using CountLeadingZeros is better or not? t = highDivisor; for (; 0 <= (Long)t; t <<= 1) { ++cc; } lowResult = MathEx.BigDivInternal( lowDividend >> (ULong_Misc.BitSizeAsIntUnchecked - cc) | (highDividend << cc), highDividend >> (ULong_Misc.BitSizeAsIntUnchecked - cc), (lowDivisor >> (ULong_Misc.BitSizeAsIntUnchecked - cc)) | t); } t = lowResult * highDivisor; lowProduct = MathEx.BigMul(lowResult, lowDivisor, out highProduct); highProduct += t; if (t > highProduct || highProduct > highDividend) { goto L_0001; } if (highDividend > highProduct || lowProduct <= lowDividend) { goto L_0002; } L_0001: --lowResult; highProduct = ((lowDivisor > lowProduct) ? (highProduct - highDivisor - 1u) : (highProduct - highDivisor)); lowProduct -= lowDivisor; L_0002: highResult = ((lowProduct > lowDividend) ? (highDividend - highProduct - 1u) : (highDividend - highProduct)); return(lowDividend - lowProduct); } else { highResult = 0u; if (highDivisor <= highDividend && (highDivisor != highDividend || lowDivisor <= lowDividend)) { return(MathEx.SubtractUnchecked(lowDividend, highDividend, lowDivisor, highDivisor, out highResult)); } else { highResult = highDividend; return(lowDividend); } } } else { highResult = 0u; return(MathEx.BigRemInternal(lowDividend, highDividend % lowDivisor, lowDivisor)); } } }
// 109 Cyc (special inpot set test6) public static ULong Remainder(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong highResult) { unchecked { if (0u != highDivisor) { if (0 <= (Long)highDivisor) { ULong lowProduct; ULong highProduct; ULong lowResult; ULong t; { int cc; #if (NET5_0 || NET6_0 || NET5_0_OR_GREATER) cc = BinaryNumerals.CountLeadingZeros(highDivisor); t = highDivisor << cc; #else // CountLeadingZeros // ? using CountLeadingZeros is better or not? cc = 0; t = highDivisor; for (; 0 <= (Long)t; t <<= 1) { ++cc; } #endif lowResult = MathEx.BigDivInternal( lowDividend >> (Misc.ULong.BitSize - cc) | (highDividend << cc), highDividend >> (Misc.ULong.BitSize - cc), (lowDivisor >> (Misc.ULong.BitSize - cc)) | t); } t = lowResult * highDivisor; lowProduct = MathEx.BigMul(lowResult, lowDivisor, out highProduct); highProduct += t; if (t > highProduct || highProduct > highDividend) { goto L_0001; } if (highDividend > highProduct || lowProduct <= lowDividend) { goto L_0002; } L_0001: --lowResult; highProduct = ((lowDivisor > lowProduct) ? (highProduct - highDivisor - 1u) : (highProduct - highDivisor)); lowProduct -= lowDivisor; L_0002: highResult = ((lowProduct > lowDividend) ? (highDividend - highProduct - 1u) : (highDividend - highProduct)); return(lowDividend - lowProduct); } else { highResult = 0u; if (highDivisor <= highDividend && (highDivisor != highDividend || lowDivisor <= lowDividend)) { return(MathEx.SubtractUnchecked(lowDividend, highDividend, lowDivisor, highDivisor, out highResult)); } else { highResult = highDividend; return(lowDividend); } } } else { highResult = 0u; return(MathEx.BigRemInternal(lowDividend, highDividend % lowDivisor, lowDivisor)); } } }