Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/limbo/model/gp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#ifndef LIMBO_MODEL_GP_HPP
#define LIMBO_MODEL_GP_HPP

#ifdef _WIN32
#include <corecrt_math_defines.h> // This brings in the M_PI define which is not in the C or C++ standard.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the following alternative:

#define _USE_MATH_DEFINES
#include <cmath>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't appear to be working for me, I get "M_PI": identifier not found. I think the issue is that if <cmath> has already been included somewhere earlier in the compilation then:

#define _USE_MATH_DEFINES
#include <cmath>

will have no effect. You have to make sure that #define _USE_MATH_DEFINES happens before the first inclusion of <cmath> which can be difficult for a header-only library.

This same issue is discussed here and here

How would you feel about skipping the use of the M_PI preprocessor constant altogether and instead use something like:

namespace limbo {
  constexpr double PI = 3.14159265359;
  ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most probably you need to put it here: https://github.com/resibots/limbo/blob/master/src/limbo/tools/math.hpp#L50. If this is not working, please enabling editing by admins for the PR and I will make the define from waf to be globally defined.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about skipping the use of the M_PI preprocessor constant altogether and instead use something like

My issue with that is that we would need to define a bigger set of constants, otherwise we are inconsistent. And this is a Windows issue. We will find a way to by-pass it.

@nickanthony-dgl nickanthony-dgl Dec 20, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting it in math.hpp didn't work but putting it in bo_base.hpp (the only place I see where gp.hpp is used) did. Please see the most recent commit.

I will go ahead and enable editing on this PR. Edit: It looks like "Allow edits by maintainers" is already enabled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the effort! I will try to have a look asap!

#endif

#include <cassert>
#include <iostream>
#include <limits>
Expand Down
11 changes: 11 additions & 0 deletions src/limbo/tools/sys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@

#include <ctime>
#include <string>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

namespace limbo {
namespace tools {
Expand All @@ -69,9 +73,16 @@ namespace limbo {
inline std::string hostname()
{
char hostname[50];
#ifdef _WIN32
DWORD buffCharCount = 50;
bool ok = GetComputerNameA(hostname, &buffCharCount);
assert(ok);
#else
int res = gethostname(hostname, 50);
assert(res == 0);
res = 0; // avoid a warning in opt mode
#endif

return std::string(hostname);
}

Expand Down