Skip to content

CppCheck exp and log #10876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EnergyPlus/FluidCoolers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ void CalcFluidCoolerOutlet(
Real64 NumTransferUnits = UAdesign / CapacityRatioMin;
Real64 ETA = std::pow(NumTransferUnits, 0.22);
Real64 A = CapacityRatio * NumTransferUnits / ETA;
Real64 effectiveness = 1.0 - std::exp((std::exp(-A) - 1.0) / (CapacityRatio / ETA));
Real64 effectiveness = 1.0 - std::exp(std::expm1(-A) / (CapacityRatio / ETA));

// calculate water to air heat transfer
_Qactual = effectiveness * CapacityRatioMin * (_InletWaterTemp - InletAirTemp);
Expand Down
6 changes: 3 additions & 3 deletions src/EnergyPlus/FuelCellElectricGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3068,7 +3068,7 @@ namespace FuelCellElectricGenerator {
this->ExhaustHX.THXexh =
((1.0 - NdotCpAuxMix / NdotCpWater) / (std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - NdotCpAuxMix / NdotCpWater)) *
TauxMix +
((std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - 1.0) /
(std::expm1(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) /
(std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - NdotCpAuxMix / NdotCpWater)) *
TwaterIn;

Expand Down Expand Up @@ -3113,7 +3113,7 @@ namespace FuelCellElectricGenerator {
this->ExhaustHX.THXexh =
((1.0 - NdotCpAuxMix / NdotCpWater) / (std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - NdotCpAuxMix / NdotCpWater)) *
TauxMix +
((std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - 1.0) /
(std::expm1(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) /
(std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - NdotCpAuxMix / NdotCpWater)) *
TwaterIn;

Expand Down Expand Up @@ -3174,7 +3174,7 @@ namespace FuelCellElectricGenerator {
this->ExhaustHX.THXexh = ((1.0 - NdotCpAuxMix / NdotCpWater) /
(std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - NdotCpAuxMix / NdotCpWater)) *
TauxMix +
((std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - 1.0) /
(std::expm1(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) /
(std::exp(UAeff * (1.0 / NdotCpAuxMix - 1.0 / NdotCpWater)) - NdotCpAuxMix / NdotCpWater)) *
TwaterIn;

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/HVACVariableRefrigerantFlow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14968,7 +14968,7 @@ void VRFCondenserEquipment::VRFOU_PipeLossC(
Pipe_Coe_k1 = Pipe_Num_Nu * Pipe_viscosity_ref;
Pipe_Coe_k3 = RefPipInsH * (this->RefPipDiaSuc + 2 * this->RefPipInsThi);
if (this->RefPipInsThi >= 0.0) {
Pipe_Coe_k2 = 2 * this->RefPipInsCon / std::log(1.0 + 2 * this->RefPipInsThi / this->RefPipDiaSuc);
Pipe_Coe_k2 = 2 * this->RefPipInsCon / std::log1p(2 * this->RefPipInsThi / this->RefPipDiaSuc);
} else {
Pipe_Coe_k2 = 9999.9;
}
Expand Down
8 changes: 4 additions & 4 deletions src/EnergyPlus/HeatRecovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ namespace HeatRecovery {
} break;
case HXConfiguration::CrossFlowBothUnmixed: { // CROSS FLOW BOTH UNMIXED
Temp = Z * std::pow(NTU, -0.22);
Eps = 1.0 - std::exp((std::exp(-NTU * Temp) - 1.0) / Temp);
Eps = 1.0 - std::exp(std::expm1(-NTU * Temp) / Temp);
} break;
case HXConfiguration::CrossFlowOther: { // CROSS FLOW, Cmax MIXED, Cmin UNMIXED
Eps = (1.0 - std::exp(-Z * (1.0 - std::exp(-NTU)))) / Z;
Expand Down Expand Up @@ -3221,13 +3221,13 @@ namespace HeatRecovery {
}
} break;
case HXConfiguration::ParallelFlow: { // PARALLEL FLOW
NTU = -std::log(-Eps - Eps * Z + 1.0) / (Z + 1.0);
NTU = -std::log1p(-Eps - Eps * Z) / (Z + 1.0);
} break;
case HXConfiguration::CrossFlowBothUnmixed: { // CROSS FLOW BOTH UNMIXED
NTU = GetNTUforCrossFlowBothUnmixed(state, Eps, Z);
} break;
case HXConfiguration::CrossFlowOther: { // CROSS FLOW, Cmax MIXED, Cmin UNMIXED
NTU = -std::log(1.0 + std::log(1.0 - Eps * Z) / Z);
NTU = -std::log1p(std::log(1.0 - Eps * Z) / Z);
} break;
default: {
ShowFatalError(state, format("HeatRecovery: Illegal flow arrangement in CalculateNTUfromEpsAndZ, Value={}", FlowArr));
Expand Down Expand Up @@ -3273,7 +3273,7 @@ namespace HeatRecovery {
int SolFla; // Flag of solver
Real64 constexpr NTU0(0.0); // lower bound for NTU
Real64 constexpr NTU1(50.0); // upper bound for NTU
auto f = [Eps, Z](Real64 const NTU) { return 1.0 - std::exp((std::exp(-std::pow(NTU, 0.78) * Z) - 1.0) / Z * std::pow(NTU, 0.22)) - Eps; };
auto f = [Eps, Z](Real64 const NTU) { return 1.0 - std::exp(std::expm1(-std::pow(NTU, 0.78) * Z) / Z * std::pow(NTU, 0.22)) - Eps; };
General::SolveRoot(state, Acc, MaxIte, SolFla, NTU, f, NTU0, NTU1);

if (SolFla == -2) {
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/Photovoltaics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ namespace Photovoltaics {
Real64 FUN(0.0);

if (((VV + II * RSER) / AA) < 700.0) {
FUN = II - IL + IO * (std::exp((VV + II * RSER) / AA) - 1.0) - ((VV + II * RSER) / state.dataPhotovoltaic->ShuntResistance);
FUN = II - IL + IO * std::expm1((VV + II * RSER) / AA) - ((VV + II * RSER) / state.dataPhotovoltaic->ShuntResistance);
} else {
ShowSevereError(state, "EquivalentOneDiode Photovoltaic model failed to find maximum power point");
ShowContinueError(state, "Numerical solver failed trying to take exponential of too large a number");
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/PlantHeatExchangerFluidToFluid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ void HeatExchangerStruct::calculate(EnergyPlusData &state, Real64 const SupSideM
this->Effectiveness = 1.0;
}
} else {
this->Effectiveness = 1.0 - std::exp((std::pow(NTU, 0.22) / CapRatio) * (std::exp(-CapRatio * std::pow(NTU, 0.78)) - 1.0));
this->Effectiveness = 1.0 - std::exp((std::pow(NTU, 0.22) / CapRatio) * std::expm1(-CapRatio * std::pow(NTU, 0.78)));
this->Effectiveness = min(1.0, this->Effectiveness);
}

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/SolarCollectors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ namespace SolarCollectors {
Real64 FpULTest;

if ((1.0 + FRULpTest / mCpATest) > 0.0) {
FpULTest = -mCpATest * std::log(1.0 + FRULpTest / mCpATest);
FpULTest = -mCpATest * std::log1p(FRULpTest / mCpATest);
} else {
FpULTest = FRULpTest; // Avoid LOG( <0 )
}
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/VariableSpeedCoils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8256,7 +8256,7 @@ namespace VariableSpeedCoils {
To1 = aa + LatentCapacityTimeConstant;
Error = 1.0;
while (Error > 0.001) {
To2 = aa - LatentCapacityTimeConstant * (std::exp(-To1 / LatentCapacityTimeConstant) - 1.0);
To2 = aa - LatentCapacityTimeConstant * std::expm1(-To1 / LatentCapacityTimeConstant);
Error = std::abs((To2 - To1) / To1);
To1 = To2;
}
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/WaterCoils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4431,11 +4431,11 @@ void CoilOutletStreamCondition(EnergyPlusData &state,
if (effectiveness < 0.0) effectiveness = 0.0;
}
} else {
d = ((std::exp(-NTU * RatioStreamCapacity * eta) - 1.0) / (RatioStreamCapacity * eta));
d = (std::expm1(-NTU * RatioStreamCapacity * eta) / (RatioStreamCapacity * eta));
if (d < -20.0 || d > 0.0) {
effectiveness = 1.0;
} else {
effectiveness = 1.0 - std::exp((std::exp(-NTU * RatioStreamCapacity * eta) - 1.0) / (RatioStreamCapacity * eta));
effectiveness = 1.0 - std::exp(std::expm1(-NTU * RatioStreamCapacity * eta) / (RatioStreamCapacity * eta));
if (effectiveness < 0.0) effectiveness = 0.0;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/EnergyPlus/WaterThermalTanks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7623,7 +7623,7 @@ Real64 WaterThermalTankData::CalcTempIntegral(Real64 const Ti, // Initial tank t
b = -(UA / Cp + m1 + m2) / m;

// Integral of T(t) = (a / b + Ti) * EXP(b * t) - a / b, evaluated from 0 to t
dTsum = (a / b + Ti) * (std::exp(b * t) - 1.0) / b - a * t / b;
dTsum = (a / b + Ti) * std::expm1(b * t) / b - a * t / b;
}

CalcTempIntegral = dTsum;
Expand Down Expand Up @@ -8084,8 +8084,8 @@ void WaterThermalTankData::CalcWaterThermalTankStratified(EnergyPlusData &state)
FinalFactorMixing = dt / NodeCapacitance;
AvgFactorMixing = FinalFactorMixing / 2.0;
} else {
FinalFactorMixing = (exp(A[k] * dt) - 1.0) / A[k] / NodeCapacitance;
AvgFactorMixing = ((exp(A[k] * dt) - 1.0) / A[k] / dt - 1.0) / A[k] / NodeCapacitance;
FinalFactorMixing = std::expm1(A[k] * dt) / A[k] / NodeCapacitance;
AvgFactorMixing = (std::expm1(A[k] * dt) / A[k] / dt - 1.0) / A[k] / NodeCapacitance;
}
const Real64 Q_AdiabaticMixing = (Tmixed - Tfinal[k]) / FinalFactorMixing;
Tfinal[k] = Tmixed;
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/WaterToAirHeatPump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,7 @@ namespace WaterToAirHeatPump {
To1 = aa + heatPump.LatentCapacityTimeConstant;
Error = 1.0;
while (Error > 0.001) {
To2 = aa - heatPump.LatentCapacityTimeConstant * (std::exp(-To1 / heatPump.LatentCapacityTimeConstant) - 1.0);
To2 = aa - heatPump.LatentCapacityTimeConstant * std::expm1(-To1 / heatPump.LatentCapacityTimeConstant);
Error = std::abs((To2 - To1) / To1);
To1 = To2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/WaterToAirHeatPumpSimple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3768,7 +3768,7 @@ namespace WaterToAirHeatPumpSimple {
To1 = aa + LatentCapacityTimeConstant;
Error = 1.0;
while (Error > 0.001) {
To2 = aa - LatentCapacityTimeConstant * (std::exp(-To1 / LatentCapacityTimeConstant) - 1.0);
To2 = aa - LatentCapacityTimeConstant * std::expm1(-To1 / LatentCapacityTimeConstant);
Error = std::abs((To2 - To1) / To1);
To1 = To2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/WaterUse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ namespace WaterUse {
case HeatRecovHX::CrossFlow: { // Unmixed
Real64 CapacityRatio = MinCapacityRate / max(DrainCapacityRate, HXCapacityRate);
Real64 NTU = this->HXUA / MinCapacityRate;
this->Effectiveness = 1.0 - std::exp((std::pow(NTU, 0.22) / CapacityRatio) * (std::exp(-CapacityRatio * std::pow(NTU, 0.78)) - 1.0));
this->Effectiveness = 1.0 - std::exp((std::pow(NTU, 0.22) / CapacityRatio) * std::expm1(-CapacityRatio * std::pow(NTU, 0.78)));
} break;
default:
break;
Expand Down
Loading