#ticket #1513 added asin() support
This commit is contained in:
commit
f36af278d0
|
@ -55,11 +55,11 @@ double MathLib::toDoubleNumber(const std::string &str)
|
||||||
{
|
{
|
||||||
return std::strtoul(str.c_str(), '\0', 16);
|
return std::strtoul(str.c_str(), '\0', 16);
|
||||||
}
|
}
|
||||||
// nullcheck
|
// nullcheck
|
||||||
else if (str == "-0" || str == "-0.0" || str == "-0."
|
else if (str == "-0" || str == "-0.0" || str == "-0."
|
||||||
|| str == "+0" || str == "+0.0" || str == "+0.")
|
|| str == "+0" || str == "+0.0" || str == "+0.")
|
||||||
return 0.0;
|
return 0.0;
|
||||||
// otherwise, convert to double
|
// otherwise, convert to double
|
||||||
std::istringstream istr(str.c_str());
|
std::istringstream istr(str.c_str());
|
||||||
double ret;
|
double ret;
|
||||||
istr >> ret;
|
istr >> ret;
|
||||||
|
|
|
@ -230,11 +230,8 @@ void Tokenizer::createTokens(std::istream &code)
|
||||||
// Read one byte at a time from code and create tokens
|
// Read one byte at a time from code and create tokens
|
||||||
for (char ch = (char)code.get(); code.good(); ch = (char)code.get())
|
for (char ch = (char)code.get(); code.good(); ch = (char)code.get())
|
||||||
{
|
{
|
||||||
// We are not handling UTF and stuff like that. Code is supposed to plain simple text.
|
|
||||||
if (ch < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// char/string..
|
// char/string..
|
||||||
|
// multiline strings are not handled. The preprocessor should handle that for us.
|
||||||
if (ch == '\'' || ch == '\"')
|
if (ch == '\'' || ch == '\"')
|
||||||
{
|
{
|
||||||
std::string line;
|
std::string line;
|
||||||
|
@ -247,9 +244,6 @@ void Tokenizer::createTokens(std::istream &code)
|
||||||
// Append token..
|
// Append token..
|
||||||
line += c;
|
line += c;
|
||||||
|
|
||||||
if (c == '\n')
|
|
||||||
++lineno;
|
|
||||||
|
|
||||||
// Special sequence '\.'
|
// Special sequence '\.'
|
||||||
if (special)
|
if (special)
|
||||||
special = false;
|
special = false;
|
||||||
|
|
|
@ -71,7 +71,11 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create tokens from code.
|
* Create tokens from code.
|
||||||
* @param code input stream for code, same as what tokenize()
|
* The code must be preprocessed first:
|
||||||
|
* - multiline strings are not handled.
|
||||||
|
* - UTF in the code are not handled.
|
||||||
|
* - comments are not handled.
|
||||||
|
* @param code input stream for code
|
||||||
*/
|
*/
|
||||||
void createTokens(std::istream &code);
|
void createTokens(std::istream &code);
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,9 @@ private:
|
||||||
ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.0E+1"));
|
ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.0E+1"));
|
||||||
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.0E-1"));
|
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.0E-1"));
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// to double number:
|
// to double number:
|
||||||
// -----------------
|
// -----------------
|
||||||
ASSERT_EQUALS(10.0 , MathLib::toDoubleNumber("10"));
|
ASSERT_EQUALS(10.0 , MathLib::toDoubleNumber("10"));
|
||||||
ASSERT_EQUALS(1000.0, MathLib::toDoubleNumber("10E+2"));
|
ASSERT_EQUALS(1000.0, MathLib::toDoubleNumber("10E+2"));
|
||||||
ASSERT_EQUALS(100.0 , MathLib::toDoubleNumber("1.0E+2"));
|
ASSERT_EQUALS(100.0 , MathLib::toDoubleNumber("1.0E+2"));
|
||||||
|
|
|
@ -2169,7 +2169,7 @@ private:
|
||||||
|
|
||||||
void mathfunctionCall1()
|
void mathfunctionCall1()
|
||||||
{
|
{
|
||||||
// log|log10
|
// log|log10
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::cout << log(-2) << std::endl;\n"
|
" std::cout << log(-2) << std::endl;\n"
|
||||||
|
@ -2230,7 +2230,7 @@ private:
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("", errout.str());
|
TODO_ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// acos
|
// acos
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::cout << acos(1) << std::endl;\n"
|
" std::cout << acos(1) << std::endl;\n"
|
||||||
|
|
|
@ -43,9 +43,9 @@ protected:
|
||||||
|
|
||||||
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
||||||
|
|
||||||
// the vars expected and actual need to be of type double, in order to avoid overflow of unsigned int
|
// the vars expected and actual need to be of type double, in order to avoid overflow of unsigned int
|
||||||
// e.g: ASSERT_EQUALS(-100.0, MathLib::toDoubleNumber("-1.0E+2")); whould not work without this.
|
// e.g: ASSERT_EQUALS(-100.0, MathLib::toDoubleNumber("-1.0E+2")); whould not work without this.
|
||||||
void assertEquals(const char *filename, int linenr, double expected, double actual);
|
void assertEquals(const char *filename, int linenr, double expected, double actual);
|
||||||
|
|
||||||
void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
||||||
void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
||||||
|
|
Loading…
Reference in New Issue