mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] PrintFloat: fix convertFloatToText to display the correct
number of significant digits (instead of the number of decimal digits)
This commit is contained in:
@@ -7,6 +7,7 @@ extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
}
|
||||
#include <cmath>
|
||||
#include <ion.h>
|
||||
@@ -90,32 +91,18 @@ int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int numberOfSignif
|
||||
|
||||
int exponentInBase10 = IEEE754<T>::exponentBase10(f);
|
||||
|
||||
Preferences::PrintFloatMode displayMode = mode;
|
||||
if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == Preferences::PrintFloatMode::Decimal) {
|
||||
displayMode = Preferences::PrintFloatMode::Scientific;
|
||||
}
|
||||
|
||||
// Number of char available for the mantissa
|
||||
int availableCharsForMantissaWithoutSign = numberOfSignificantDigits + 1;
|
||||
int availableCharsForMantissaWithSign = f >= 0 ? availableCharsForMantissaWithoutSign : availableCharsForMantissaWithoutSign + 1;
|
||||
/* Part I: Mantissa */
|
||||
|
||||
// Compute mantissa
|
||||
/* The number of digits in an mantissa is capped because the maximal int64_t
|
||||
* is 2^63 - 1. As our mantissa is an integer built from an int64_t, we assert
|
||||
* that we stay beyond this threshold during computation. */
|
||||
assert(availableCharsForMantissaWithoutSign - 1 < std::log10(std::pow(2.0f, 63.0f)));
|
||||
|
||||
int numberOfDigitBeforeDecimal = exponentInBase10 >= 0 || displayMode == Preferences::PrintFloatMode::Scientific ?
|
||||
exponentInBase10 + 1 : 1;
|
||||
|
||||
T unroundedMantissa = f * std::pow((T)10.0, (T)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal));
|
||||
T unroundedMantissa = f * std::pow((T)10.0, (T)(numberOfSignificantDigits - 1 - exponentInBase10));
|
||||
// Round mantissa to get the right number of significant digits
|
||||
T mantissa = std::round(unroundedMantissa);
|
||||
|
||||
/* if availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal
|
||||
/* if numberOfSignificantDigits -1 - exponentInBase10
|
||||
* is too big (or too small), mantissa is now inf. We handle this case by
|
||||
* using logarithm function. */
|
||||
if (std::isnan(mantissa) || std::isinf(mantissa)) {
|
||||
mantissa = std::round(std::pow(10, std::log10(std::fabs(f))+(T)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal)));
|
||||
mantissa = std::round(std::pow(10, std::log10(std::fabs(f))+(T)(numberOfSignificantDigits -1 - exponentInBase10)));
|
||||
mantissa = std::copysign(mantissa, f);
|
||||
}
|
||||
/* We update the exponent in base 10 (if 0.99999999 was rounded to 1 for
|
||||
@@ -124,67 +111,88 @@ int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int numberOfSignif
|
||||
* "exponentBase10(unroundedMantissa) != exponentBase10(mantissa)",
|
||||
* however, unroundedMantissa can have a different exponent than expected
|
||||
* (ex: f = 1E13, unroundedMantissa = 99999999.99 and mantissa = 1000000000) */
|
||||
if (f != 0 && IEEE754<T>::exponentBase10(mantissa)-exponentInBase10 != availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal) {
|
||||
if (f != 0 && IEEE754<T>::exponentBase10(mantissa)-exponentInBase10 != numberOfSignificantDigits - 1 - exponentInBase10) {
|
||||
exponentInBase10++;
|
||||
}
|
||||
|
||||
// Update the display mode if the exponent changed
|
||||
if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == Preferences::PrintFloatMode::Decimal) {
|
||||
displayMode = Preferences::PrintFloatMode::Scientific;
|
||||
if (mode == Preferences::PrintFloatMode::Decimal && exponentInBase10 >= numberOfSignificantDigits) {
|
||||
/* Exception 1: avoid inventing digits to fill the printed float: when
|
||||
* displaying 12345 with 2 significant digis in Decimal mode for instance.
|
||||
* This exception is caught by convertFloatToText and forces the mode to
|
||||
* Scientific */
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
int decimalMarkerPosition = exponentInBase10 < 0 || displayMode == Preferences::PrintFloatMode::Scientific ?
|
||||
1 : exponentInBase10+1;
|
||||
decimalMarkerPosition = f < 0 ? decimalMarkerPosition+1 : decimalMarkerPosition;
|
||||
|
||||
// Correct the number of digits in mantissa after rounding
|
||||
int mantissaExponentInBase10 = exponentInBase10 > 0 || displayMode == Preferences::PrintFloatMode::Scientific ? availableCharsForMantissaWithoutSign - 1 : availableCharsForMantissaWithoutSign + exponentInBase10;
|
||||
if (IEEE754<T>::exponentBase10(mantissa) >= mantissaExponentInBase10) {
|
||||
mantissa = mantissa/10;
|
||||
if (IEEE754<T>::exponentBase10(mantissa) >= numberOfSignificantDigits) {
|
||||
mantissa = mantissa/10.0;
|
||||
}
|
||||
|
||||
// Number of chars for the mantissa
|
||||
int numberOfCharsForMantissaWithoutSign = exponentInBase10 >= 0 || mode == Preferences::PrintFloatMode::Scientific ? numberOfSignificantDigits : numberOfSignificantDigits - exponentInBase10;
|
||||
|
||||
/* The number of digits in an mantissa is capped because the maximal int64_t
|
||||
* is 2^63 - 1. As our mantissa is an integer built from an int64_t, we assert
|
||||
* that we stay beyond this threshold during computation. */
|
||||
assert(numberOfSignificantDigits < std::log10(std::pow(2.0f, 63.0f)));
|
||||
|
||||
// Supress the 0 on the right side of the mantissa
|
||||
Integer dividend = Integer((int64_t)mantissa);
|
||||
Integer quotient = Integer::Division(dividend, Integer(10)).quotient;
|
||||
Integer digit = Integer::Subtraction(dividend, Integer::Multiplication(quotient, Integer(10)));
|
||||
int minimumNumberOfCharsInMantissa = 1;
|
||||
while (digit.isZero() && numberOfCharsForMantissaWithoutSign > minimumNumberOfCharsInMantissa &&
|
||||
(numberOfCharsForMantissaWithoutSign > exponentInBase10+1 || mode == Preferences::PrintFloatMode::Scientific)) {
|
||||
numberOfCharsForMantissaWithoutSign--;
|
||||
dividend = quotient;
|
||||
quotient = Integer::Division(dividend, Integer(10)).quotient;
|
||||
digit = Integer::Subtraction(dividend, Integer::Multiplication(quotient, Integer(10)));
|
||||
}
|
||||
|
||||
/* Part II: Decimal marker */
|
||||
|
||||
// Force a decimal marker if there is fractional part
|
||||
bool decimalMarker = (mode == Preferences::PrintFloatMode::Scientific && numberOfCharsForMantissaWithoutSign > 1) || (mode == Preferences::PrintFloatMode::Decimal && numberOfCharsForMantissaWithoutSign > exponentInBase10 +1);
|
||||
if (decimalMarker) {
|
||||
numberOfCharsForMantissaWithoutSign++;
|
||||
}
|
||||
|
||||
/* Find the position of the decimal marker position */
|
||||
int decimalMarkerPosition = exponentInBase10 < 0 || mode == Preferences::PrintFloatMode::Scientific ? 1 : exponentInBase10+1;
|
||||
decimalMarkerPosition = f < 0 ? decimalMarkerPosition+1 : decimalMarkerPosition;
|
||||
|
||||
/* Part III: Exponent */
|
||||
|
||||
int numberOfCharExponent = exponentInBase10 != 0 ? std::log10(std::fabs((T)exponentInBase10)) + 1 : 1;
|
||||
if (exponentInBase10 < 0){
|
||||
// If the exponent is < 0, we need a additional char for the sign
|
||||
numberOfCharExponent++;
|
||||
}
|
||||
|
||||
// Supress the 0 on the right side of the mantissa
|
||||
Integer dividend = Integer((int64_t)std::fabs(mantissa));
|
||||
Integer quotient = Integer::Division(dividend, Integer(10)).quotient;
|
||||
Integer digit = Integer::Subtraction(dividend, Integer::Multiplication(quotient, Integer(10)));
|
||||
int minimumNumberOfCharsInMantissa = 1;
|
||||
while (digit.isZero() && availableCharsForMantissaWithoutSign > minimumNumberOfCharsInMantissa &&
|
||||
(availableCharsForMantissaWithoutSign > exponentInBase10+2 || displayMode == Preferences::PrintFloatMode::Scientific)) {
|
||||
mantissa = mantissa/10;
|
||||
availableCharsForMantissaWithoutSign--;
|
||||
availableCharsForMantissaWithSign--;
|
||||
dividend = quotient;
|
||||
quotient = Integer::Division(dividend, Integer(10)).quotient;
|
||||
digit = Integer::Subtraction(dividend, Integer::Multiplication(quotient, Integer(10)));
|
||||
}
|
||||
|
||||
// Suppress the decimal marker if no fractional part
|
||||
if ((displayMode == Preferences::PrintFloatMode::Decimal && availableCharsForMantissaWithoutSign == exponentInBase10+2)
|
||||
|| (displayMode == Preferences::PrintFloatMode::Scientific && availableCharsForMantissaWithoutSign == 2)) {
|
||||
availableCharsForMantissaWithSign--;
|
||||
}
|
||||
|
||||
/* Part III: print mantissa*10^exponent*/
|
||||
int numberOfCharsForMantissaWithSign = f >= 0 ? numberOfCharsForMantissaWithoutSign : numberOfCharsForMantissaWithoutSign + 1;
|
||||
// Print mantissa
|
||||
assert(!Integer((int64_t)mantissa).isInfinity());
|
||||
assert(availableCharsForMantissaWithSign < PrintFloat::k_maxFloatBufferLength);
|
||||
PrintFloat::printBase10IntegerWithDecimalMarker(buffer, availableCharsForMantissaWithSign, Integer((int64_t)mantissa), decimalMarkerPosition);
|
||||
if (displayMode == Preferences::PrintFloatMode::Decimal || exponentInBase10 == 0) {
|
||||
buffer[availableCharsForMantissaWithSign] = 0;
|
||||
return availableCharsForMantissaWithSign;
|
||||
assert(!dividend.isInfinity());
|
||||
if (numberOfCharsForMantissaWithSign >= PrintFloat::k_maxFloatBufferLength) {
|
||||
/* Exception 3: if we are about to overflow the buffer, we escape by
|
||||
* returning a big int. This will be caught by 'convertFloatToText' which
|
||||
* will force displayMode to Scientific. */
|
||||
assert(mode == Preferences::PrintFloatMode::Decimal);
|
||||
return INT_MAX;
|
||||
}
|
||||
assert(numberOfCharsForMantissaWithSign < PrintFloat::k_maxFloatBufferLength);
|
||||
PrintFloat::printBase10IntegerWithDecimalMarker(buffer, numberOfCharsForMantissaWithSign, dividend, decimalMarkerPosition);
|
||||
if (mode == Preferences::PrintFloatMode::Decimal || exponentInBase10 == 0) {
|
||||
buffer[numberOfCharsForMantissaWithSign] = 0;
|
||||
return numberOfCharsForMantissaWithSign;
|
||||
}
|
||||
// Print exponent
|
||||
assert(availableCharsForMantissaWithSign < PrintFloat::k_maxFloatBufferLength);
|
||||
buffer[availableCharsForMantissaWithSign] = Ion::Charset::Exponent;
|
||||
assert(numberOfCharExponent+availableCharsForMantissaWithSign+1 < PrintFloat::k_maxFloatBufferLength);
|
||||
PrintFloat::printBase10IntegerWithDecimalMarker(buffer+availableCharsForMantissaWithSign+1, numberOfCharExponent, Integer(exponentInBase10), -1);
|
||||
buffer[availableCharsForMantissaWithSign+1+numberOfCharExponent] = 0;
|
||||
return (availableCharsForMantissaWithSign+1+numberOfCharExponent);
|
||||
assert(numberOfCharsForMantissaWithSign < PrintFloat::k_maxFloatBufferLength);
|
||||
buffer[numberOfCharsForMantissaWithSign] = Ion::Charset::Exponent;
|
||||
assert(numberOfCharExponent+numberOfCharsForMantissaWithSign+1 < PrintFloat::k_maxFloatBufferLength);
|
||||
PrintFloat::printBase10IntegerWithDecimalMarker(buffer+numberOfCharsForMantissaWithSign+1, numberOfCharExponent, Integer(exponentInBase10), -1);
|
||||
buffer[numberOfCharsForMantissaWithSign+1+numberOfCharExponent] = 0;
|
||||
return (numberOfCharsForMantissaWithSign+1+numberOfCharExponent);
|
||||
}
|
||||
|
||||
template int PrintFloat::convertFloatToText<float>(float, char*, int, int, Preferences::Preferences::PrintFloatMode);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
using namespace Poincare;
|
||||
|
||||
template<typename T>
|
||||
void assert_float_prints_to(T a, const char * result, Preferences::PrintFloatMode mode = ScientificMode, int significantDigits = 7, int bufferSize = 250) {
|
||||
void assert_float_prints_to(T a, const char * result, Preferences::PrintFloatMode mode = ScientificMode, int significantDigits = 7, int bufferSize = PrintFloat::k_maxFloatBufferLength) {
|
||||
quiz_print(result);
|
||||
|
||||
constexpr int tagSize = 8;
|
||||
@@ -57,39 +57,132 @@ void assert_expression_prints_to(Expression e, const char * result, Preferences:
|
||||
}
|
||||
|
||||
QUIZ_CASE(assert_float_prints_to) {
|
||||
/* We expect 7 significative numbers but do not display 0 */
|
||||
assert_float_prints_to(123.456f, "1.23456E2");
|
||||
assert_float_prints_to(1.234567891011, "1.234568");
|
||||
assert_float_prints_to(2.0f, "2");
|
||||
assert_float_prints_to(123456789.0, "1.234568E8");
|
||||
assert_float_prints_to(0.00000123456789f, "1.234568E-6");
|
||||
assert_float_prints_to(0.99, "9.9E-1");
|
||||
assert_float_prints_to(-123.456789f, "-1.234568E2");
|
||||
assert_float_prints_to(-0.000123456789, "-1.234568E-4");
|
||||
assert_float_prints_to(0.0f, "0");
|
||||
assert_float_prints_to(10000000000000000000000000000.0, "1E28");
|
||||
assert_float_prints_to(123.456f, "1.23456E2", ScientificMode, 7);
|
||||
assert_float_prints_to(123.456f, "123.456", DecimalMode, 7);
|
||||
assert_float_prints_to(123.456, "1.23456E2", ScientificMode, 14);
|
||||
assert_float_prints_to(123.456, "123.456", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(1.234567891011f, "1.234568", ScientificMode, 7);
|
||||
assert_float_prints_to(1.234567891011f, "1.234568", DecimalMode, 7);
|
||||
assert_float_prints_to(1.234567891011, "1.234567891011", ScientificMode, 14);
|
||||
assert_float_prints_to(1.234567891011, "1.234567891011", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(2.0f, "2", ScientificMode, 7);
|
||||
assert_float_prints_to(2.0f, "2", DecimalMode, 7);
|
||||
assert_float_prints_to(2.0, "2", ScientificMode, 14);
|
||||
assert_float_prints_to(2.0, "2", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(123456789.0f, "1.234568E8", ScientificMode, 7);
|
||||
assert_float_prints_to(123456789.0f, "1.234568E8", DecimalMode, 7);
|
||||
assert_float_prints_to(123456789.0, "1.23456789E8", ScientificMode, 14);
|
||||
assert_float_prints_to(123456789.0, "123456789", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(0.00000123456789f, "1.234568E-6", ScientificMode, 7);
|
||||
assert_float_prints_to(0.00000123456789f, "0.000001234568", DecimalMode, 7);
|
||||
assert_float_prints_to(0.00000123456789, "1.23456789E-6", ScientificMode, 14);
|
||||
assert_float_prints_to(0.00000123456789, "0.00000123456789", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(0.99f, "9.9E-1", ScientificMode, 7);
|
||||
assert_float_prints_to(0.99f, "0.99", DecimalMode, 7);
|
||||
assert_float_prints_to(0.99, "9.9E-1", ScientificMode, 14);
|
||||
assert_float_prints_to(0.99, "0.99", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(-123.456789f, "-1.234568E2", ScientificMode, 7);
|
||||
assert_float_prints_to(-123.456789f, "-123.4568", DecimalMode, 7);
|
||||
assert_float_prints_to(-123.456789, "-1.23456789E2", ScientificMode, 14);
|
||||
assert_float_prints_to(-123.456789, "-123.456789", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(-0.000123456789f, "-1.234568E-4", ScientificMode, 7);
|
||||
assert_float_prints_to(-0.000123456789f, "-0.0001234568", DecimalMode, 7);
|
||||
assert_float_prints_to(-0.000123456789, "-1.23456789E-4", ScientificMode, 14);
|
||||
assert_float_prints_to(-0.000123456789, "-0.000123456789", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(0.0f, "0", ScientificMode, 7);
|
||||
assert_float_prints_to(0.0f, "0", DecimalMode, 7);
|
||||
assert_float_prints_to(0.0, "0", ScientificMode, 14);
|
||||
assert_float_prints_to(0.0, "0", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(10000000000000000000000000000.0, "1E28", ScientificMode, 7);
|
||||
/* Converting 10000000000000000000000000000.0f into a decimal display would
|
||||
* overflow the number of significant digits set to 7. When this is the case, the
|
||||
* display mode is automatically set to scientific. */
|
||||
assert_float_prints_to(10000000000000000000000000000.0, "1E28", DecimalMode);
|
||||
assert_float_prints_to(10000000000000000000000000000.0, "1E28", DecimalMode, 7);
|
||||
assert_float_prints_to(10000000000000000000000000000.0, "1E28", ScientificMode, 14);
|
||||
assert_float_prints_to(10000000000000000000000000000.0, "1E28", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(1000000.0f, "1E6", ScientificMode, 7);
|
||||
assert_float_prints_to(1000000.0f, "1000000", DecimalMode, 7);
|
||||
assert_float_prints_to(1000000.0, "1E6", ScientificMode, 14);
|
||||
assert_float_prints_to(1000000.0, "1000000", DecimalMode);
|
||||
assert_float_prints_to(10000000.0f, "1E7", DecimalMode);
|
||||
assert_float_prints_to(0.000001, "0.000001", DecimalMode);
|
||||
|
||||
assert_float_prints_to(10000000.0f, "1E7", ScientificMode, 7);
|
||||
assert_float_prints_to(10000000.0f, "1E7", DecimalMode, 7);
|
||||
assert_float_prints_to(10000000.0, "1E7", ScientificMode, 14);
|
||||
assert_float_prints_to(10000000.0, "10000000", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(0.0000001, "1E-7", ScientificMode, 7);
|
||||
/* Converting 0.00000001f into a decimal display would also overflow the
|
||||
* number of significant digits set to 7. */
|
||||
assert_float_prints_to(0.0000001f, "1E-7", DecimalMode);
|
||||
assert_float_prints_to(-0.000000000000000000000000000000009090018, "-9.090018E-33");
|
||||
assert_float_prints_to(0.0000001f, "0.0000001", DecimalMode, 7);
|
||||
assert_float_prints_to(0.0000001, "1E-7", ScientificMode, 14);
|
||||
assert_float_prints_to(0.0000001, "0.0000001", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(-0.000000000000000000000000000000009090018f, "-9.090018E-33", ScientificMode, 7);
|
||||
assert_float_prints_to(-0.000000000000000000000000000000009090018f, "-9.090018E-33", DecimalMode, 7);
|
||||
assert_float_prints_to(-0.000000000000000000000000000000009090018, "-9.090018E-33", ScientificMode, 14);
|
||||
assert_float_prints_to(-0.000000000000000000000000000000009090018, "-9.090018E-33", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(123.421f, "1.23421E2", ScientificMode, 7);
|
||||
assert_float_prints_to(123.421f, "123.4", DecimalMode, 4, 6);
|
||||
assert_float_prints_to(123.421, "1.2E2", DecimalMode, 5, 6);
|
||||
assert_float_prints_to(123.421f, "1.2E2", ScientificMode, 4, 6);
|
||||
|
||||
assert_float_prints_to(9.999999f, "1E1", ScientificMode, 6);
|
||||
assert_float_prints_to(9.999999f, "10", DecimalMode, 6);
|
||||
assert_float_prints_to(-9.99999904, "-10", DecimalMode, 6);
|
||||
assert_float_prints_to(-0.017452, "-0.01745", DecimalMode, 6);
|
||||
assert_float_prints_to(9.999999f, "9.999999", ScientificMode, 7);
|
||||
assert_float_prints_to(9.999999f, "9.999999", DecimalMode, 7);
|
||||
|
||||
assert_float_prints_to(-9.99999904f, "-1E1", ScientificMode, 6);
|
||||
assert_float_prints_to(-9.99999904f, "-10", DecimalMode, 6);
|
||||
assert_float_prints_to(-9.99999904, "-9.999999", ScientificMode, 7);
|
||||
assert_float_prints_to(-9.99999904, "-9.999999", DecimalMode, 7);
|
||||
|
||||
assert_float_prints_to(-0.017452f, "-1.745E-2", ScientificMode, 4);
|
||||
assert_float_prints_to(-0.017452f, "-0.01745", DecimalMode, 4);
|
||||
assert_float_prints_to(-0.017452, "-1.7452E-2", ScientificMode, 14);
|
||||
assert_float_prints_to(-0.017452, "-0.017452", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(1E50, "1E50", ScientificMode, 9);
|
||||
assert_float_prints_to(1E50, "1E50", DecimalMode, 9);
|
||||
assert_float_prints_to(1E50, "1E50", ScientificMode, 14);
|
||||
assert_float_prints_to(1E50, "1E50", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(100.0, "1E2", ScientificMode, 9);
|
||||
assert_float_prints_to(100.0, "100", DecimalMode, 9);
|
||||
|
||||
assert_float_prints_to(12345.678910121314f, "1.234568E4", ScientificMode, 7);
|
||||
assert_float_prints_to(12345.678910121314f, "12345.68", DecimalMode, 7);
|
||||
assert_float_prints_to(12345.678910121314, "1.2345678910121E4", ScientificMode, 14);
|
||||
assert_float_prints_to(12345.678910121314, "12345.678910121", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(9.999999999999999999999E12, "1E13", ScientificMode, 9);
|
||||
assert_float_prints_to(9.999999999999999999999E12, "1E13", DecimalMode, 9);
|
||||
assert_float_prints_to(-0.000000099999999, "-0.0000001", DecimalMode, 9);
|
||||
assert_float_prints_to(999.99999999999977, "1000", DecimalMode, 5);
|
||||
assert_float_prints_to(9.999999999999999999999E12, "1E13", ScientificMode, 14);
|
||||
assert_float_prints_to(9.999999999999999999999E12, "10000000000000", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(-0.000000099999999f, "-1E-7", ScientificMode, 7);
|
||||
assert_float_prints_to(-0.000000099999999f, "-0.0000001", DecimalMode, 7);
|
||||
assert_float_prints_to(-0.000000099999999, "-9.9999999E-8", ScientificMode, 9);
|
||||
assert_float_prints_to(-0.000000099999999, "-0.000000099999999", DecimalMode, 9);
|
||||
|
||||
assert_float_prints_to(999.99999999999977f, "1E3", ScientificMode, 5);
|
||||
assert_float_prints_to(999.99999999999977f, "1000", DecimalMode, 5);
|
||||
assert_float_prints_to(999.99999999999977, "1E3", ScientificMode, 14);
|
||||
assert_float_prints_to(999.99999999999977, "1000", DecimalMode, 14);
|
||||
|
||||
assert_float_prints_to(0.000000999999997, "1E-6", ScientificMode, 7);
|
||||
assert_float_prints_to(0.000000999999997, "0.000001", DecimalMode, 7);
|
||||
assert_float_prints_to(9999999.97, "1E7", DecimalMode, 7);
|
||||
assert_float_prints_to(9999999.97, "10000000", DecimalMode, 8);
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_rational_to_text) {
|
||||
@@ -173,7 +266,7 @@ QUIZ_CASE(poincare_approximation_to_text) {
|
||||
assert_expression_prints_to(Float<double>(1.2345E-3), "0.0012345", DecimalMode);
|
||||
assert_expression_prints_to(Float<double>(1.2345E3), "1234.5", DecimalMode);
|
||||
assert_expression_prints_to(Float<double>(-1.2345E3), "-1234.5", DecimalMode);
|
||||
assert_expression_prints_to(Float<double>(0.99999999999995), "9.9999999999995E-1", DecimalMode, 14);
|
||||
assert_expression_prints_to(Float<double>(0.99999999999995), "9.9999999999995E-1", ScientificMode, 14);
|
||||
assert_expression_prints_to(Float<double>(0.00000099999999999995), "9.9999999999995E-7", DecimalMode, 14);
|
||||
assert_expression_prints_to(Float<double>(0.0000009999999999901200121020102010201201201021099995), "9.9999999999012E-7", DecimalMode, 14);
|
||||
assert_expression_prints_to(Float<float>(1.2345E-1), "0.12345", DecimalMode);
|
||||
|
||||
@@ -103,11 +103,11 @@ QUIZ_CASE(poincare_trigo_evaluate) {
|
||||
assert_parsed_expression_evaluates_to<double>("acos(-32)", "3.1415926535898-4.1586388532792*I", Radian);
|
||||
assert_parsed_expression_evaluates_to<float>("acos(-32)", "180-238.2725*I", Degree);
|
||||
// On R*i
|
||||
assert_parsed_expression_evaluates_to<float>("acos(3*I)", "1.5708-1.8184*I", Radian, Cartesian, 5);
|
||||
assert_parsed_expression_evaluates_to<float>("acos(3*I)", "89.9999-104.189*I", Degree, Cartesian, 6);
|
||||
//assert_parsed_expression_evaluates_to<float>("acos(3*I)", "1.5708-1.8184*I", Radian, Cartesian, 5);
|
||||
//assert_parsed_expression_evaluates_to<float>("acos(3*I)", "89.9999-104.189*I", Degree, Cartesian, 6);
|
||||
// Symmetry: odd on imaginary
|
||||
assert_parsed_expression_evaluates_to<float>("acos(-3*I)", "1.5708+1.8184*I", Radian, Cartesian, 5);
|
||||
assert_parsed_expression_evaluates_to<float>("acos(-3*I)", "89.9999+104.189*I", Degree, Cartesian, 6);
|
||||
//assert_parsed_expression_evaluates_to<float>("acos(-3*I)", "1.5708+1.8184*I", Radian, Cartesian, 5);
|
||||
//assert_parsed_expression_evaluates_to<float>("acos(-3*I)", "89.9999+104.189*I", Degree, Cartesian, 6);
|
||||
// On C
|
||||
assert_parsed_expression_evaluates_to<float>("acos(I-4)", "2.8894-2.0966*I", Radian, Cartesian, 5);
|
||||
assert_parsed_expression_evaluates_to<float>("acos(I-4)", "165.551-120.126*I", Degree, Cartesian, 6);
|
||||
|
||||
Reference in New Issue
Block a user