diff --git a/apps/calculation/additional_outputs/complex_graph_cell.cpp b/apps/calculation/additional_outputs/complex_graph_cell.cpp index 46dee7f6d..4436d784d 100644 --- a/apps/calculation/additional_outputs/complex_graph_cell.cpp +++ b/apps/calculation/additional_outputs/complex_graph_cell.cpp @@ -39,7 +39,7 @@ void ComplexGraphView::drawRect(KDContext * ctx, KDRect rect) const { * and the line of equation (real*t,imag*t). * (a*cos(t), b*sin(t)) = (real*t,imag*t) --> tan(t) = sign(a)*sign(b) (± π) * --> t = π/4 [π/2] according to sign(a) and sign(b). */ - float th = real < 0.0f ? 3.0f*M_PI/4.0f : M_PI/4.0f; + float th = real < 0.0f ? 3.0f*(float)M_PI/4.0f : (float)M_PI/4.0f; th = imag < 0.0f ? -th : th; // Compute ellipsis parameters a and b float factor = 5.0f; @@ -48,7 +48,7 @@ void ComplexGraphView::drawRect(KDContext * ctx, KDRect rect) const { // Avoid flat ellipsis for edge cases (for real = 0, the case imag = 0 is excluded) if (real == 0.0f) { a = 1.0f/factor; - th = imag < 0.0f ? -M_PI/2.0f : M_PI/2.0f; + th = imag < 0.0f ? -(float)M_PI/2.0f : (float)M_PI/2.0f; } std::complex parameters(a,b); drawCurve(ctx, rect, 0.0f, 1.0f, 0.01f, diff --git a/apps/calculation/additional_outputs/trigonometry_model.h b/apps/calculation/additional_outputs/trigonometry_model.h index cf31fb1f8..c299565a8 100644 --- a/apps/calculation/additional_outputs/trigonometry_model.h +++ b/apps/calculation/additional_outputs/trigonometry_model.h @@ -18,7 +18,7 @@ public: float yMax() const override { return yCenter() + yHalfRange(); } void setAngle(float f) { m_angle = f; } - float angle() const { return m_angle*M_PI/Poincare::Trigonometry::PiInAngleUnit(Poincare::Preferences::sharedPreferences()->angleUnit()); } + float angle() const { return m_angle*(float)M_PI/(float)Poincare::Trigonometry::PiInAngleUnit(Poincare::Preferences::sharedPreferences()->angleUnit()); } private: constexpr static float k_xHalfRange = 2.1f; // We center the yRange around the semi-circle where the angle is diff --git a/apps/probability/distribution/binomial_distribution.cpp b/apps/probability/distribution/binomial_distribution.cpp index ed1e8f213..5ee9326e0 100644 --- a/apps/probability/distribution/binomial_distribution.cpp +++ b/apps/probability/distribution/binomial_distribution.cpp @@ -66,7 +66,7 @@ double BinomialDistribution::cumulativeDistributiveInverseForProbability(double } double BinomialDistribution::rightIntegralInverseForProbability(double * probability) { - if (m_parameter1 == 0.0 && (m_parameter2 == 0.0 || m_parameter2 == 1.0)) { + if (m_parameter1 == 0.0f && (m_parameter2 == 0.0f || m_parameter2 == 1.0f)) { return NAN; } if (*probability <= 0.0) { diff --git a/apps/probability/distribution/chi_squared_distribution.cpp b/apps/probability/distribution/chi_squared_distribution.cpp index 091cf30f2..450d7804a 100644 --- a/apps/probability/distribution/chi_squared_distribution.cpp +++ b/apps/probability/distribution/chi_squared_distribution.cpp @@ -44,7 +44,7 @@ double ChiSquaredDistribution::cumulativeDistributiveFunctionAtAbscissa(double x return 0.0; } double result = 0.0; - if (regularizedGamma(m_parameter1/2.0, x/2.0, k_regularizedGammaPrecision, k_maxRegularizedGammaIterations, &result)) { + if (regularizedGamma(m_parameter1/2.0f, x/2.0, k_regularizedGammaPrecision, k_maxRegularizedGammaIterations, &result)) { return result; } return NAN; diff --git a/apps/probability/distribution/student_distribution.cpp b/apps/probability/distribution/student_distribution.cpp index 4199f4467..bfeff60fd 100644 --- a/apps/probability/distribution/student_distribution.cpp +++ b/apps/probability/distribution/student_distribution.cpp @@ -23,7 +23,7 @@ float StudentDistribution::evaluateAtAbscissa(float x) const { } bool StudentDistribution::authorizedValueAtIndex(float x, int index) const { - return x >= FLT_EPSILON && x <= 200.0; // We cannot draw the curve for x > 200 (coefficient() is too small) + return x >= FLT_EPSILON && x <= 200.0f; // We cannot draw the curve for x > 200 (coefficient() is too small) } double StudentDistribution::cumulativeDistributiveFunctionAtAbscissa(double x) const { diff --git a/apps/shared/function_graph_view.cpp b/apps/shared/function_graph_view.cpp index 587a49fcb..7e111f2bf 100644 --- a/apps/shared/function_graph_view.cpp +++ b/apps/shared/function_graph_view.cpp @@ -69,8 +69,8 @@ void FunctionGraphView::reloadBetweenBounds(float start, float end) { if (start == end) { return; } - float pixelLowerBound = floatToPixel(Axis::Horizontal, start)-2.0; - float pixelUpperBound = floatToPixel(Axis::Horizontal, end)+4.0; + float pixelLowerBound = floatToPixel(Axis::Horizontal, start) - 2.0f; + float pixelUpperBound = floatToPixel(Axis::Horizontal, end) + 4.0f; /* We exclude the banner frame from the dirty zone to avoid unnecessary * redrawing */ KDRect dirtyZone(KDRect(pixelLowerBound, 0, pixelUpperBound-pixelLowerBound, diff --git a/poincare/include/poincare/ieee754.h b/poincare/include/poincare/ieee754.h index d2e25d6ce..c1b3c0bcc 100644 --- a/poincare/include/poincare/ieee754.h +++ b/poincare/include/poincare/ieee754.h @@ -53,7 +53,7 @@ public: } static int exponentBase10(T f) { static T k_log10base2 = 3.321928094887362347870319429489390175864831393024580612054; - if (f == 0.0) { + if (f == (T)0.0) { return 0; } T exponentBase2 = exponent(f); @@ -68,7 +68,7 @@ public: * in -0.31 < x < 1, we get: * e2 = [e1/log(10,2)] or e2 = [e1/log(10,2)]-1 depending on m1. */ int exponentBase10 = std::round(exponentBase2/k_log10base2); - if (std::pow(10.0, exponentBase10) > std::fabs(f)) { + if (std::pow((T)10.0, exponentBase10) > std::fabs(f)) { exponentBase10--; } return exponentBase10; diff --git a/poincare/src/approximation_helper.cpp b/poincare/src/approximation_helper.cpp index c82371cb4..30439ad9c 100644 --- a/poincare/src/approximation_helper.cpp +++ b/poincare/src/approximation_helper.cpp @@ -19,7 +19,7 @@ template < typename T> T minimalNonNullMagnitudeOfParts(std::complex c) { T absRealInput = std::fabs(c.real()); T absImagInput = std::fabs(c.imag()); // If the magnitude of one part is null, ignore it - if (absRealInput == 0.0 || (absImagInput > 0.0 && absImagInput < absRealInput)) { + if (absRealInput == (T)0.0 || (absImagInput > (T)0.0 && absImagInput < absRealInput)) { return absImagInput; } return absRealInput; @@ -52,7 +52,7 @@ template std::complex ApproximationHelper::NeglectRealOrImaginar } T magnitude1 = minimalNonNullMagnitudeOfParts(input1); T magnitude2 = minimalNonNullMagnitudeOfParts(input2); - T precision = 10.0*Expression::Epsilon(); + T precision = ((T)10.0)*Expression::Epsilon(); if (isNegligeable(result.imag(), precision, magnitude1, magnitude2)) { result.imag(0); } diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index 9f27e4f5d..b7bd085ae 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -26,7 +26,7 @@ Expression ArcCosineNode::shallowReduce(ReductionContext reductionContext) { template Complex ArcCosineNode::computeOnComplex(const std::complex c, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) { std::complex result; - if (c.imag() == 0 && std::fabs(c.real()) <= 1.0) { + if (c.imag() == 0 && std::fabs(c.real()) <= (T)1.0) { /* acos: [-1;1] -> R * In these cases we rather use std::acos(double) because acos on complexes * is not as precise as pow on double in std library. For instance, diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index 4d7100ac8..7168da4e1 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -26,7 +26,7 @@ Expression ArcSineNode::shallowReduce(ReductionContext reductionContext) { template Complex ArcSineNode::computeOnComplex(const std::complex c, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) { std::complex result; - if (c.imag() == 0 && std::fabs(c.real()) <= 1.0) { + if (c.imag() == 0 && std::fabs(c.real()) <= (T)1.0) { /* asin: [-1;1] -> R * In these cases we rather use std::asin(double) because asin on complexes * is not as precise as asin on double in std library. For instance, diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index 19bb310bb..cdfda478f 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -22,7 +22,7 @@ int ArcTangentNode::serialize(char * buffer, int bufferSize, Preferences::PrintF template Complex ArcTangentNode::computeOnComplex(const std::complex c, Preferences::ComplexFormat, Preferences::AngleUnit angleUnit) { std::complex result; - if (c.imag() == 0 && std::fabs(c.real()) <= 1.0) { + if (c.imag() == 0 && std::fabs(c.real()) <= (T)1.0) { /* atan: R -> R * In these cases we rather use std::atan(double) because atan on complexes * is not as precise as atan on double in std library. For instance, diff --git a/poincare/src/complex.cpp b/poincare/src/complex.cpp index b78b6fc69..a9e022101 100644 --- a/poincare/src/complex.cpp +++ b/poincare/src/complex.cpp @@ -26,7 +26,7 @@ ComplexNode::ComplexNode(std::complex c) : EvaluationNode(), std::complex(c.real(), c.imag()) { - if (!std::isnan(c.imag()) && c.imag() != 0.0) { + if (!std::isnan(c.imag()) && c.imag() != (T)0.0) { Expression::SetEncounteredComplex(true); } if (this->real() == -0) { @@ -39,7 +39,7 @@ ComplexNode::ComplexNode(std::complex c) : template T ComplexNode::toScalar() const { - if (this->imag() == 0.0) { + if (this->imag() == (T)0.0) { return this->real(); } return NAN; @@ -63,7 +63,7 @@ Expression ComplexNode::complexToExpression(Preferences::ComplexFormat comple Number::DecimalNumber(std::fabs(tb)), complexFormat, (std::isnan(this->real()) || std::isnan(this->imag())), - ra == 0.0, std::fabs(ra) == 1.0, tb == 0.0, std::fabs(tb) == 1.0, ra < 0.0, tb < 0.0 + ra == (T)0.0, std::fabs(ra) == (T)1.0, tb == (T)0.0, std::fabs(tb) == (T)1.0, ra < (T)0.0, tb < (T)0.0 ); } diff --git a/poincare/src/complex_cartesian.cpp b/poincare/src/complex_cartesian.cpp index 0d8933192..da5db5d74 100644 --- a/poincare/src/complex_cartesian.cpp +++ b/poincare/src/complex_cartesian.cpp @@ -35,7 +35,7 @@ Complex ComplexCartesianNode::templatedApproximate(Context * context, Prefere assert(imagEvalution.type() == EvaluationNode::Type::Complex); std::complex a = static_cast &>(realEvaluation).stdComplex(); std::complex b = static_cast &>(imagEvalution).stdComplex(); - if ((a.imag() != 0.0 && !std::isnan(a.imag())) || (b.imag() != 0.0 && !std::isnan(b.imag()))) { + if ((a.imag() != (T)0.0 && !std::isnan(a.imag())) || (b.imag() != (T)0.0 && !std::isnan(b.imag()))) { /* a and b are supposed to be real (if they are not undefined). However, * due to double precision limit, the approximation of the real part or the * imaginary part can lead to complex values. diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index a5e208150..3a9b857a8 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -56,7 +56,7 @@ Evaluation DerivativeNode::templatedApproximate(Context * context, Preference do { T currentError; T currentResult = riddersApproximation(context, complexFormat, angleUnit, evaluationArgument, h, ¤tError); - h /= 10.0; + h /= (T)10.0; if (std::isnan(currentError) || currentError > error) { continue; } diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index b7011ffb4..77ff4c825 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -47,7 +47,7 @@ Expression DivisionNode::shallowReduce(ReductionContext reductionContext) { } template Complex DivisionNode::compute(const std::complex c, const std::complex d, Preferences::ComplexFormat complexFormat) { - if (d.real() == 0.0 && d.imag() == 0.0) { + if (d.real() == (T)0.0 && d.imag() == (T)0.0) { return Complex::Undefined(); } return Complex::Builder(c/d); diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index adf6defbf..55641980a 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -128,8 +128,8 @@ IntegralNode::DetailedResult IntegralNode::kronrodGaussQuadrature(T a, T b, C T fv1[10]; T fv2[10]; - T center = 0.5 * (a+b); - T halfLength = 0.5 * (b-a); + T center = (T)0.5 * (a+b); + T halfLength = (T)0.5 * (b-a); T absHalfLength = std::fabs(halfLength); DetailedResult errorResult; @@ -163,7 +163,7 @@ IntegralNode::DetailedResult IntegralNode::kronrodGaussQuadrature(T a, T b, C absKronrodIntegral += wKronrod[j] * (std::fabs(fval1) + std::fabs(fval2)); } - T halfKronrodIntegral = 0.5 * kronrodIntegral; + T halfKronrodIntegral = (T)0.5 * kronrodIntegral; T kronrodIntegralDifference = wKronrod[10] * std::fabs(fCenter - halfKronrodIntegral); for (int j = 0; j < 10; j++) { kronrodIntegralDifference += wKronrod[j] * (std::fabs(fv1[j] - halfKronrodIntegral) + std::fabs(fv2[j] - halfKronrodIntegral)); @@ -176,7 +176,7 @@ IntegralNode::DetailedResult IntegralNode::kronrodGaussQuadrature(T a, T b, C T errorCoefficient = std::pow((T)(200*absError/kronrodIntegralDifference), (T)1.5); absError = 1 > errorCoefficient ? kronrodIntegralDifference * errorCoefficient : kronrodIntegralDifference; } - if (absKronrodIntegral > max/(50.0 * epsilon)) { + if (absKronrodIntegral > max/((T)50.0 * epsilon)) { T minError = epsilon * 50 * absKronrodIntegral; absError = absError > minError ? absError : minError; } diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index b6297c1e3..803dfc18d 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -279,7 +279,7 @@ Expression Logarithm::simpleShallowReduce(Context * context, Preferences::Comple if (logDenominator.imag() != 0.0f || logDenominator.real() == 0.0f) { result = Undefined::Builder(); } - isNegative = logDenominator.real() > 0.0; + isNegative = logDenominator.real() > 0.0f; result = result.isUninitialized() ? Infinity::Builder(isNegative) : result; replaceWithInPlace(result); return result; diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index e34393aef..dfdaedc3f 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -270,7 +270,7 @@ void Matrix::ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, // No non-null coefficient in this column, skip k++; // Update determinant: det *= 0 - if (determinant) { *determinant *= 0.0; } + if (determinant) { *determinant *= (T)0.0; } } else { // Swap row h and iPivot if (iPivot != h) { @@ -281,7 +281,7 @@ void Matrix::ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, array[h*numberOfColumns+col] = temp; } // Update determinant: det *= -1 - if (determinant) { *determinant *= -1.0; } + if (determinant) { *determinant *= (T)-1.0; } } // Set to 1 array[h][k] by linear combination T divisor = array[h*numberOfColumns+k]; diff --git a/poincare/src/normal_distribution.cpp b/poincare/src/normal_distribution.cpp index 0d27f41a3..ba62b1dca 100644 --- a/poincare/src/normal_distribution.cpp +++ b/poincare/src/normal_distribution.cpp @@ -5,6 +5,8 @@ #include #include +#define M_SQRT_2PI 2.506628274631000502415765284811 + namespace Poincare { template @@ -13,7 +15,7 @@ T NormalDistribution::EvaluateAtAbscissa(T x, T mu, T sigma) { return NAN; } const float xMinusMuOverVar = (x - mu)/sigma; - return ((T)1.0)/(std::fabs(sigma) * std::sqrt(((T)2.0) * M_PI)) * std::exp(-((T)0.5) * xMinusMuOverVar * xMinusMuOverVar); + return ((T)1.0)/(std::fabs(sigma) * (T)M_SQRT_2PI) * std::exp(-((T)0.5) * xMinusMuOverVar * xMinusMuOverVar); } template @@ -95,7 +97,7 @@ T NormalDistribution::StandardNormalCumulativeDistributiveFunctionAtAbscissa(T a if (abscissa < (T)0.0) { return ((T)1.0) - StandardNormalCumulativeDistributiveFunctionAtAbscissa(-abscissa); } - return ((T)0.5) + ((T)0.5) * std::erf(abscissa/std::sqrt(((T)2.0))); + return ((T)0.5) + ((T)0.5) * std::erf(abscissa/(T)M_SQRT2); } template @@ -113,7 +115,7 @@ T NormalDistribution::StandardNormalCumulativeDistributiveInverseForProbability( if (probability < (T)0.5) { return -StandardNormalCumulativeDistributiveInverseForProbability(((T)1.0)-probability); } - return std::sqrt((T)2.0) * erfInv(((T)2.0) * probability - (T)1.0); + return (T)M_SQRT2 * erfInv(((T)2.0) * probability - (T)1.0); } template float NormalDistribution::EvaluateAtAbscissa(float, float, float); diff --git a/poincare/src/number.cpp b/poincare/src/number.cpp index 0136cb545..42c1cac17 100644 --- a/poincare/src/number.cpp +++ b/poincare/src/number.cpp @@ -72,7 +72,7 @@ Number Number::DecimalNumber(T f) { return Undefined::Builder(); } if (std::isinf(f)) { - return Infinity::Builder(f < 0.0); + return Infinity::Builder(f < (T)0.0); } return Decimal::Builder(f); } diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index fa7e3c755..9ccc0eed5 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -136,7 +136,7 @@ Complex PowerNode::computeNotPrincipalRealRootOfRationalPow(const std::comple * where the principal root is real as these cases are handled generically * later (for instance 1232^(1/8) which has a real principal root is not * handled here). */ - if (c.imag() == 0 && std::pow((T)-1.0, q) < 0.0) { + if (c.imag() == (T)0.0 && std::pow((T)-1.0, q) < (T)0.0) { /* If c real and q odd integer (q odd if (-1)^q = -1), a real root does * exist (which is not necessarily the principal root)! * For q even integer, a real root does not necessarily exist (example: @@ -148,7 +148,7 @@ Complex PowerNode::computeNotPrincipalRealRootOfRationalPow(const std::comple /* As q is odd, c^(p/q) = (sign(c)^(1/q))^p * |c|^(p/q) * = sign(c)^p * |c|^(p/q) * = -|c|^(p/q) iff c < 0 and p odd */ - return c.real() < 0 && std::pow((T)-1.0, p) < 0.0 ? Complex::Builder(-absCPowD.stdComplex()) : absCPowD; + return c.real() < (T)0.0 && std::pow((T)-1.0, p) < (T)0.0 ? Complex::Builder(-absCPowD.stdComplex()) : absCPowD; } return Complex::Undefined(); } @@ -156,7 +156,7 @@ Complex PowerNode::computeNotPrincipalRealRootOfRationalPow(const std::comple template Complex PowerNode::compute(const std::complex c, const std::complex d, Preferences::ComplexFormat complexFormat) { std::complex result; - if (c.imag() == 0.0 && d.imag() == 0.0 && c.real() != 0.0 && (c.real() > 0.0 || std::round(d.real()) == d.real())) { + if (c.imag() == (T)0.0 && d.imag() == (T)0.0 && c.real() != (T)0.0 && (c.real() > (T)0.0 || std::round(d.real()) == d.real())) { /* pow: (R+, R) -> R+ (2^1.3 ~ 2.46) * pow: (R-, N) -> R+ ((-2)^3 = -8) * In these cases we rather use std::pow(double, double) because: diff --git a/poincare/src/prediction_interval.cpp b/poincare/src/prediction_interval.cpp index f3bad4750..0893818e6 100644 --- a/poincare/src/prediction_interval.cpp +++ b/poincare/src/prediction_interval.cpp @@ -40,8 +40,8 @@ Evaluation PredictionIntervalNode::templatedApproximate(Context * context, Pr return Complex::RealUndefined(); } std::complex operands[2]; - operands[0] = std::complex(p - 1.96*std::sqrt(p*(1.0-p))/std::sqrt(n)); - operands[1] = std::complex(p + 1.96*std::sqrt(p*(1.0-p))/std::sqrt(n)); + operands[0] = std::complex(p - (T)1.96*std::sqrt(p*((T)1.0-p))/std::sqrt(n)); + operands[1] = std::complex(p + (T)1.96*std::sqrt(p*((T)1.0-p))/std::sqrt(n)); return MatrixComplex::Builder(operands, 1, 2); } diff --git a/poincare/src/print_float.cpp b/poincare/src/print_float.cpp index c34f64420..fefad549d 100644 --- a/poincare/src/print_float.cpp +++ b/poincare/src/print_float.cpp @@ -238,7 +238,7 @@ PrintFloat::TextLengths PrintFloat::ConvertFloatToTextPrivate(T f, char * buffer // Correct the number of digits in mantissa after rounding if (IEEE754::exponentBase10(mantissa) >= numberOfSignificantDigits) { - mantissa = mantissa/10.0; + mantissa = mantissa / (T)10.0; } // Number of chars for the mantissa diff --git a/poincare/src/randint.cpp b/poincare/src/randint.cpp index 148aae3bd..52d15e7f9 100644 --- a/poincare/src/randint.cpp +++ b/poincare/src/randint.cpp @@ -49,10 +49,10 @@ template Evaluation RandintNode::templateApproximate(Context * c if (std::isnan(a) || std::isnan(b) || std::isinf(a) || std::isinf(b) || a > b || a != (int)a || b != (int)b - || (Expression::Epsilon()*(b+1.0-a) > 1.0)) { + || (Expression::Epsilon()*(b+(T)1.0-a) > (T)1.0)) { return Complex::RealUndefined(); } - T result = std::floor(Random::random()*(b+1.0-a)+a); + T result = std::floor(Random::random()*(b+(T)1.0-a)+a); return Complex::Builder(result); } diff --git a/poincare/src/solver.cpp b/poincare/src/solver.cpp index 33914717e..a5ea72bc3 100644 --- a/poincare/src/solver.cpp +++ b/poincare/src/solver.cpp @@ -230,11 +230,11 @@ T Solver::CumulativeDistributiveInverseForNDefinedFunction(T * probability, Valu do { delta = std::fabs(*probability-p); p += evaluation(k++, context, complexFormat, angleUnit, context1, context2, context3); - if (p >= k_maxProbability && std::fabs(*probability-1.0) <= delta) { + if (p >= k_maxProbability && std::fabs(*probability-(T)1.0) <= delta) { *probability = (T)1.0; return (T)(k-1); } - } while (std::fabs(*probability-p) <= delta && k < k_maxNumberOfOperations && p < 1.0); + } while (std::fabs(*probability-p) <= delta && k < k_maxNumberOfOperations && p < (T)1.0); p -= evaluation(--k, context, complexFormat, angleUnit, context1, context2, context3); if (k == k_maxNumberOfOperations) { *probability = (T)1.0; diff --git a/poincare/src/trigonometry.cpp b/poincare/src/trigonometry.cpp index 168f7e49d..7ece0a2cc 100644 --- a/poincare/src/trigonometry.cpp +++ b/poincare/src/trigonometry.cpp @@ -399,7 +399,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Expressio template std::complex Trigonometry::ConvertToRadian(const std::complex c, Preferences::AngleUnit angleUnit) { if (angleUnit != Preferences::AngleUnit::Radian) { - return c * std::complex(M_PI/Trigonometry::PiInAngleUnit(angleUnit)); + return c * std::complex((T)M_PI/(T)Trigonometry::PiInAngleUnit(angleUnit)); } return c; } @@ -407,7 +407,7 @@ std::complex Trigonometry::ConvertToRadian(const std::complex c, Preferenc template std::complex Trigonometry::ConvertRadianToAngleUnit(const std::complex c, Preferences::AngleUnit angleUnit) { if (angleUnit != Preferences::AngleUnit::Radian) { - return c * std::complex(Trigonometry::PiInAngleUnit(angleUnit)/M_PI); + return c * std::complex((T)Trigonometry::PiInAngleUnit(angleUnit)/(T)M_PI); } return c; }