mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Infinity::Name() gives "inf"
This commit is contained in:
@@ -49,6 +49,12 @@ public:
|
||||
node()->setNegative(negative);
|
||||
}
|
||||
Expression setSign(ExpressionNode::Sign s, Context & context, Preferences::AngleUnit angleUnit);
|
||||
static const char * Name() {
|
||||
return "inf";
|
||||
}
|
||||
static int NameSize() {
|
||||
return 4;
|
||||
}
|
||||
private:
|
||||
InfinityNode * node() const { return static_cast<InfinityNode *>(Number::node()); }
|
||||
};
|
||||
|
||||
@@ -140,11 +140,16 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
if (currentChar >= bufferSize-1) { return bufferSize-1; }
|
||||
}
|
||||
int mantissaLength = m.serialize(tempBuffer, PrintFloat::k_numberOfStoredSignificantDigits+1);
|
||||
assert(strcmp(tempBuffer, "inf") != 0 && strcmp(tempBuffer, "-inf") != 0);
|
||||
|
||||
// Assert that m is not +/-inf
|
||||
assert(strcmp(tempBuffer, Infinity::Name()) != 0);
|
||||
assert(!(tempBuffer[0] == '-' && strcmp(&tempBuffer[1], Infinity::Name()) == 0));
|
||||
|
||||
if (strcmp(tempBuffer, Undefined::Name()) == 0) {
|
||||
currentChar += strlcpy(buffer+currentChar, tempBuffer, bufferSize-currentChar);
|
||||
return currentChar;
|
||||
}
|
||||
|
||||
/* We force scientific mode if the number of digits before the dot is superior
|
||||
* to the number of significant digits (ie with 4 significant digits,
|
||||
* 12345 -> 1.235E4 or 12340 -> 1.234E4). */
|
||||
|
||||
@@ -38,7 +38,7 @@ bool Parser::IsSpecialIdentifierName(const char * name, size_t nameLength) {
|
||||
// TODO Avoid special cases if possible
|
||||
return (
|
||||
Token::CompareNonNullTerminatedName(name, nameLength, Symbol::k_ans) == 0 ||
|
||||
Token::CompareNonNullTerminatedName(name, nameLength, "inf") == 0 ||
|
||||
Token::CompareNonNullTerminatedName(name, nameLength, Infinity::Name()) == 0 ||
|
||||
Token::CompareNonNullTerminatedName(name, nameLength, Undefined::Name()) == 0 ||
|
||||
Token::CompareNonNullTerminatedName(name, nameLength, "u_") == 0 ||
|
||||
Token::CompareNonNullTerminatedName(name, nameLength, "v_") == 0 ||
|
||||
@@ -347,7 +347,7 @@ void Parser::parseSequence(Expression & leftHandSide, const char name, Token::Ty
|
||||
void Parser::parseSpecialIdentifier(Expression & leftHandSide) {
|
||||
if (m_currentToken.compareTo(Symbol::k_ans) == 0) {
|
||||
leftHandSide = Symbol::Ans();
|
||||
} else if (m_currentToken.compareTo("inf") == 0) {
|
||||
} else if (m_currentToken.compareTo(Infinity::Name()) == 0) {
|
||||
leftHandSide = Infinity(false);
|
||||
} else if (m_currentToken.compareTo(Undefined::Name()) == 0) {
|
||||
leftHandSide = Undefined();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <poincare/print_float.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <poincare/ieee754.h>
|
||||
#include <poincare/infinity.h>
|
||||
#include <poincare/integer.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <poincare/undefined.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
@@ -11,8 +12,6 @@ extern "C" {
|
||||
#include <limits.h>
|
||||
}
|
||||
#include <cmath>
|
||||
#include <ion.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -68,18 +67,16 @@ template <class T>
|
||||
int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int numberOfSignificantDigits, Preferences::PrintFloatMode mode) {
|
||||
assert(numberOfSignificantDigits > 0);
|
||||
if (std::isinf(f)) {
|
||||
assert(Infinity::NameSize()+1 < PrintFloat::k_maxFloatBufferLength);
|
||||
int currentChar = 0;
|
||||
if (f < 0) {
|
||||
buffer[currentChar++] = '-';
|
||||
}
|
||||
buffer[currentChar++] = 'i';
|
||||
buffer[currentChar++] = 'n';
|
||||
buffer[currentChar++] = 'f';
|
||||
buffer[currentChar] = 0;
|
||||
return currentChar;
|
||||
strlcpy(&buffer[currentChar], Infinity::Name(), PrintFloat::k_maxFloatBufferLength-1);
|
||||
return currentChar + Infinity::NameSize() - 1;
|
||||
}
|
||||
|
||||
if (std::isinf(f) || std::isnan(f)) {
|
||||
if (std::isnan(f)) {
|
||||
assert(Undefined::NameSize() < PrintFloat::k_maxFloatBufferLength);
|
||||
strlcpy(buffer, Undefined::Name(), PrintFloat::k_maxFloatBufferLength);
|
||||
return Undefined::NameSize() - 1;
|
||||
|
||||
@@ -281,7 +281,7 @@ QUIZ_CASE(poincare_approximation_to_text) {
|
||||
assert_expression_prints_to(Float<float>(0.0000009999999999999995), "0.000001", DecimalMode);
|
||||
assert_expression_prints_to(Float<float>(-1.2345E-1), "-0.12345", DecimalMode);
|
||||
|
||||
assert_expression_prints_to(Float<double>(INFINITY), "inf", DecimalMode);
|
||||
assert_expression_prints_to(Float<double>(INFINITY), Infinity::Name(), DecimalMode);
|
||||
assert_expression_prints_to(Float<float>(0.0f), "0", DecimalMode);
|
||||
assert_expression_prints_to(Float<float>(NAN), Undefined::Name(), DecimalMode);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ QUIZ_CASE(poincare_float_evaluate) {
|
||||
assert_float_evaluates_to<float>(Float<float>(0.0000009999999999999995), "0.000001");
|
||||
assert_float_evaluates_to<float>(Float<float>(-1.2345E-1), "-0.12345");
|
||||
|
||||
assert_float_evaluates_to<double>(Float<double>(INFINITY), "inf");
|
||||
assert_float_evaluates_to<double>(Float<double>(INFINITY), Infinity::Name());
|
||||
assert_float_evaluates_to<float>(Float<float>(0.0f), "0");
|
||||
assert_float_evaluates_to<float>(Float<float>(NAN), Undefined::Name());
|
||||
|
||||
|
||||
@@ -238,11 +238,11 @@ QUIZ_CASE(poincare_function_simplify) {
|
||||
assert_parsed_expression_simplify_to("ceil(-1.3)", "-1");
|
||||
assert_parsed_expression_simplify_to("conj(1/2)", "1/2");
|
||||
assert_parsed_expression_simplify_to("quo(19,3)", "6");
|
||||
assert_parsed_expression_simplify_to("quo(19,0)", "inf");
|
||||
assert_parsed_expression_simplify_to("quo(19,0)", Infinity::Name());
|
||||
assert_parsed_expression_simplify_to("quo(-19,3)", "-7");
|
||||
assert_parsed_expression_simplify_to("rem(19,3)", "1");
|
||||
assert_parsed_expression_simplify_to("rem(-19,3)", "2");
|
||||
assert_parsed_expression_simplify_to("rem(19,0)", "inf");
|
||||
assert_parsed_expression_simplify_to("rem(19,0)", Infinity::Name());
|
||||
assert_parsed_expression_simplify_to("99!", "933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000");
|
||||
assert_parsed_expression_simplify_to("factor(-10008/6895)", "-(2^3*3^2*139)/(5*7*197)");
|
||||
assert_parsed_expression_simplify_to("factor(1008/6895)", "(2^4*3^2)/(5*197)");
|
||||
|
||||
@@ -268,5 +268,5 @@ QUIZ_CASE(poincare_integer_serialize) {
|
||||
assert_integer_serializes_to(Integer("2345678909876"), "2345678909876");
|
||||
assert_integer_serializes_to(Integer("-2345678909876"), "-2345678909876");
|
||||
assert_integer_serializes_to(MaxInteger(), MaxIntegerString());
|
||||
assert_integer_serializes_to(OverflowedInteger(), "inf");
|
||||
assert_integer_serializes_to(OverflowedInteger(), Infinity::Name());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ QUIZ_CASE(poincare_logarithm_simplify) {
|
||||
assert_parsed_expression_simplify_to("log(1,0)", "0");
|
||||
assert_parsed_expression_simplify_to("log(2,0)", "0");
|
||||
assert_parsed_expression_simplify_to("log(0,14)", "-inf");
|
||||
assert_parsed_expression_simplify_to("log(0,0.14)", "inf");
|
||||
assert_parsed_expression_simplify_to("log(0,0.14)", Infinity::Name());
|
||||
assert_parsed_expression_simplify_to("log(0,0.14+I)", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("log(2,1)", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("log(x,1)", Undefined::Name());
|
||||
|
||||
@@ -267,7 +267,7 @@ QUIZ_CASE(poincare_parser_symbols_and_functions) {
|
||||
assert_parsed_expression_is("I", Constant(Ion::Charset::IComplex));
|
||||
assert_parsed_expression_is("P", Constant(Ion::Charset::SmallPi));
|
||||
assert_parsed_expression_is("X", Constant(Ion::Charset::Exponential));
|
||||
assert_parsed_expression_is("inf", Infinity(false));
|
||||
assert_parsed_expression_is(Infinity::Name(), Infinity(false));
|
||||
assert_parsed_expression_is(Undefined::Name(), Undefined());
|
||||
|
||||
assert_raises_parsing_error("u");
|
||||
|
||||
@@ -93,8 +93,8 @@ QUIZ_CASE(poincare_rational_simplify) {
|
||||
// MaxIntegerString()
|
||||
assert_parsed_expression_simplify_to(MaxIntegerString(), MaxIntegerString());
|
||||
// OverflowedIntegerString()
|
||||
assert_parsed_expression_simplify_to(BigOverflowedIntegerString(), "inf");
|
||||
assert_parsed_expression_simplify_to(BigOverflowedIntegerString(), "inf");
|
||||
assert_parsed_expression_simplify_to(BigOverflowedIntegerString(), Infinity::Name());
|
||||
assert_parsed_expression_simplify_to(BigOverflowedIntegerString(), Infinity::Name());
|
||||
// -OverflowedIntegerString()
|
||||
buffer[0] = '-';
|
||||
strlcpy(buffer+1, BigOverflowedIntegerString(), 400-1);
|
||||
@@ -143,5 +143,5 @@ QUIZ_CASE(poincare_rational_serialize) {
|
||||
Integer one(1);
|
||||
Integer overflow = Integer::Overflow(false);
|
||||
assert_parsed_expression_serialize_to(Rational(one, overflow), "1/inf");
|
||||
assert_parsed_expression_serialize_to(Rational(overflow), "inf");
|
||||
assert_parsed_expression_serialize_to(Rational(overflow), Infinity::Name());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user