📄 epd.c
字号:
Synopsis [Computes arbitrary precision pow of base 2.] Description [Computes arbitrary precision pow of base 2.] SideEffects [] SeeAlso []******************************************************************************/voidEpdPow2(int n, EpDouble *epd){ if (n <= EPD_MAX_BIN) { EpdConvert(pow((double)2.0, (double)n), epd); } else { EpDouble epd1, epd2; int n1, n2; n1 = n / 2; n2 = n - n1; EpdPow2(n1, &epd1); EpdPow2(n2, &epd2); EpdMultiply3(&epd1, &epd2, epd); }}/**Function******************************************************************** Synopsis [Computes arbitrary precision pow of base 2.] Description [Computes arbitrary precision pow of base 2.] SideEffects [] SeeAlso []******************************************************************************/voidEpdPow2Decimal(int n, EpDouble *epd){ if (n <= EPD_MAX_BIN) { epd->type.value = pow((double)2.0, (double)n); epd->exponent = 0; EpdNormalizeDecimal(epd); } else { EpDouble epd1, epd2; int n1, n2; n1 = n / 2; n2 = n - n1; EpdPow2Decimal(n1, &epd1); EpdPow2Decimal(n2, &epd2); EpdMultiply3Decimal(&epd1, &epd2, epd); }}/**Function******************************************************************** Synopsis [Normalize an arbitrary precision double value.] Description [Normalize an arbitrary precision double value.] SideEffects [] SeeAlso []******************************************************************************/voidEpdNormalize(EpDouble *epd){ int exponent; if (IsNanOrInfDouble(epd->type.value)) { epd->exponent = 0; return; } exponent = EpdGetExponent(epd->type.value); if (exponent == EPD_MAX_BIN) return; exponent -= EPD_MAX_BIN; epd->type.bits.exponent = EPD_MAX_BIN; epd->exponent += exponent;}/**Function******************************************************************** Synopsis [Normalize an arbitrary precision double value.] Description [Normalize an arbitrary precision double value.] SideEffects [] SeeAlso []******************************************************************************/voidEpdNormalizeDecimal(EpDouble *epd){ int exponent; if (IsNanOrInfDouble(epd->type.value)) { epd->exponent = 0; return; } exponent = EpdGetExponentDecimal(epd->type.value); epd->type.value /= pow((double)10.0, (double)exponent); epd->exponent += exponent;}/**Function******************************************************************** Synopsis [Returns value and decimal exponent of EpDouble.] Description [Returns value and decimal exponent of EpDouble.] SideEffects [] SeeAlso []******************************************************************************/voidEpdGetValueAndDecimalExponent(EpDouble *epd, double *value, int *exponent){ EpDouble epd1, epd2; if (EpdIsNanOrInf(epd)) return; if (EpdIsZero(epd)) { *value = 0.0; *exponent = 0; return; } epd1.type.value = epd->type.value; epd1.exponent = 0; EpdPow2Decimal(epd->exponent, &epd2); EpdMultiply2Decimal(&epd1, &epd2); *value = epd1.type.value; *exponent = epd1.exponent;}/**Function******************************************************************** Synopsis [Returns the exponent value of a double.] Description [Returns the exponent value of a double.] SideEffects [] SeeAlso []******************************************************************************/intEpdGetExponent(double value){ int exponent; EpDouble epd; epd.type.value = value; exponent = epd.type.bits.exponent; return(exponent);}/**Function******************************************************************** Synopsis [Returns the decimal exponent value of a double.] Description [Returns the decimal exponent value of a double.] SideEffects [] SeeAlso []******************************************************************************/intEpdGetExponentDecimal(double value){ char *pos, str[24]; int exponent; sprintf(str, "%E", value); pos = strstr(str, "E"); sscanf(pos, "E%d", &exponent); return(exponent);}/**Function******************************************************************** Synopsis [Makes EpDouble Inf.] Description [Makes EpDouble Inf.] SideEffects [] SeeAlso []******************************************************************************/voidEpdMakeInf(EpDouble *epd, int sign){ epd->type.bits.mantissa1 = 0; epd->type.bits.mantissa0 = 0; epd->type.bits.exponent = EPD_EXP_INF; epd->type.bits.sign = sign; epd->exponent = 0;}/**Function******************************************************************** Synopsis [Makes EpDouble Zero.] Description [Makes EpDouble Zero.] SideEffects [] SeeAlso []******************************************************************************/voidEpdMakeZero(EpDouble *epd, int sign){ epd->type.bits.mantissa1 = 0; epd->type.bits.mantissa0 = 0; epd->type.bits.exponent = 0; epd->type.bits.sign = sign; epd->exponent = 0;}/**Function******************************************************************** Synopsis [Makes EpDouble NaN.] Description [Makes EpDouble NaN.] SideEffects [] SeeAlso []******************************************************************************/voidEpdMakeNan(EpDouble *epd){ epd->type.nan.mantissa1 = 0; epd->type.nan.mantissa0 = 0; epd->type.nan.quiet_bit = 1; epd->type.nan.exponent = EPD_EXP_INF; epd->type.nan.sign = 1; epd->exponent = 0;}/**Function******************************************************************** Synopsis [Copies a EpDouble struct.] Description [Copies a EpDouble struct.] SideEffects [] SeeAlso []******************************************************************************/voidEpdCopy(EpDouble *from, EpDouble *to){ to->type.value = from->type.value; to->exponent = from->exponent;}/**Function******************************************************************** Synopsis [Checks whether the value is Inf.] Description [Checks whether the value is Inf.] SideEffects [] SeeAlso []******************************************************************************/intEpdIsInf(EpDouble *epd){ return(IsInfDouble(epd->type.value));}/**Function******************************************************************** Synopsis [Checks whether the value is Zero.] Description [Checks whether the value is Zero.] SideEffects [] SeeAlso []******************************************************************************/intEpdIsZero(EpDouble *epd){ if (epd->type.value == 0.0) return(1); else return(0);}/**Function******************************************************************** Synopsis [Checks whether the value is NaN.] Description [Checks whether the value is NaN.] SideEffects [] SeeAlso []******************************************************************************/intEpdIsNan(EpDouble *epd){ return(IsNanDouble(epd->type.value));}/**Function******************************************************************** Synopsis [Checks whether the value is NaN or Inf.] Description [Checks whether the value is NaN or Inf.] SideEffects [] SeeAlso []******************************************************************************/intEpdIsNanOrInf(EpDouble *epd){ return(IsNanOrInfDouble(epd->type.value));}/**Function******************************************************************** Synopsis [Checks whether the value is Inf.] Description [Checks whether the value is Inf.] SideEffects [] SeeAlso []******************************************************************************/intIsInfDouble(double value){ IeeeDouble *ptr = (IeeeDouble *)(&value); if (ptr->exponent == EPD_EXP_INF && ptr->mantissa0 == 0 && ptr->mantissa1 == 0) { if (ptr->sign == 0) return(1); else return(-1); } return(0);}/**Function******************************************************************** Synopsis [Checks whether the value is NaN.] Description [Checks whether the value is NaN.] SideEffects [] SeeAlso []******************************************************************************/intIsNanDouble(double value){ IeeeNan *ptr = (IeeeNan *)(&value); if (ptr->exponent == EPD_EXP_INF && ptr->sign == 1 && ptr->quiet_bit == 1 && ptr->mantissa0 == 0 && ptr->mantissa1 == 0) { return(1); } return(0);}/**Function******************************************************************** Synopsis [Checks whether the value is NaN or Inf.] Description [Checks whether the value is NaN or Inf.] SideEffects [] SeeAlso []******************************************************************************/intIsNanOrInfDouble(double value){ IeeeNan *ptr = (IeeeNan *)(&value); if (ptr->exponent == EPD_EXP_INF && ptr->mantissa0 == 0 && ptr->mantissa1 == 0 && (ptr->sign == 1 || ptr->quiet_bit == 0)) { return(1); } return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -