Skip to content

Commit da3bb98

Browse files
Use a portable PI constant in generated code
Co-Authored-By: zemanadam893@gmail.com <zemanadam893@gmail.com>
1 parent bc7d499 commit da3bb98

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎src/engine/internal/cpp/cppcodebuilder.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,17 +398,17 @@ CompilerValue *CppCodeBuilder::createTan(CompilerValue *num)
398398

399399
CompilerValue *CppCodeBuilder::createAsin(CompilerValue *num)
400400
{
401-
return mathFunction(num, "std::asin", " * 180.0 / M_PI + 0.0");
401+
return mathFunction(num, "std::asin", " * 180.0 / cpp::PI + 0.0");
402402
}
403403

404404
CompilerValue *CppCodeBuilder::createAcos(CompilerValue *num)
405405
{
406-
return mathFunction(num, "std::acos", " * 180.0 / M_PI");
406+
return mathFunction(num, "std::acos", " * 180.0 / cpp::PI");
407407
}
408408

409409
CompilerValue *CppCodeBuilder::createAtan(CompilerValue *num)
410410
{
411-
return mathFunction(num, "std::atan", " * 180.0 / M_PI");
411+
return mathFunction(num, "std::atan", " * 180.0 / cpp::PI");
412412
}
413413

414414
CompilerValue *CppCodeBuilder::createLn(CompilerValue *num)

‎src/engine/internal/cpp/cppprelude.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct Frame
6363
int state = 0;
6464
};
6565

66+
static constexpr double PI = 3.14159265358979323846;
67+
6668
struct Str
6769
{
6870
Str() :
@@ -231,12 +233,12 @@ inline double round(double x)
231233

232234
inline double sin(double x)
233235
{
234-
return std::round(std::sin(x * M_PI / 180.0) * 1e10) / 1e10 + 0.0;
236+
return std::round(std::sin(x * PI / 180.0) * 1e10) / 1e10 + 0.0;
235237
}
236238

237239
inline double cos(double x)
238240
{
239-
return std::round(std::cos(x * M_PI / 180.0) * 1e10) / 1e10;
241+
return std::round(std::cos(x * PI / 180.0) * 1e10) / 1e10;
240242
}
241243

242244
inline double tan(double x)
@@ -248,7 +250,7 @@ inline double tan(double x)
248250
else if (m == -90.0 || m == 270.0)
249251
return -std::numeric_limits<double>::infinity();
250252

251-
return std::round(std::tan(x * M_PI / 180.0) * 1e10) / 1e10 + 0.0;
253+
return std::round(std::tan(x * PI / 180.0) * 1e10) / 1e10 + 0.0;
252254
}
253255

254256
inline double random(ExecutionContext *ctx, double from, double to)

0 commit comments

Comments
 (0)