Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math::softfloat::float64_t( <float_value> ) or math::softfloat::float64_t(<double_value>) possible? #110

Closed
RobertMassart opened this issue Jan 11, 2024 · 3 comments

Comments

@RobertMassart
Copy link

RobertMassart commented Jan 11, 2024

In a cpp header I want to have the following work:

inline constexpr auto gravitational_constant = math::softfloat::float64_t(6.674e-11);

// This will work when it's an integer value
inline constexpr auto gravitational_constant = math::softfloat::float64_t(6);

Just can't use constexpr when it's a double or float.

Is it possible to make this work as an constexpr?

@ckormanyos
Copy link
Owner

Is it possible to make this work as an constexpr?

Yes @RobertMassart there are several options for this to work. One of them is to make the constructor from the internal 64-bit representation type to be public. I'll see qhich option is best, and we can discuss further.

@RobertMassart
Copy link
Author

I did find in VS2022 it was an "invalid access to an inactive member" so to fix this I change the following:

at line 394:

From:
explicit constexpr uz_type(float_type f) noexcept : my_f(f) { }

To:
explicit constexpr uz_type(float_type f) noexcept : my_u{}, my_f(f) { }

@ckormanyos
Copy link
Owner

ckormanyos commented Jan 13, 2024

Hi Robert (@RobertMassart), I used a standard C++20 function to do a preliminary (yet portable) fix for this. The only real condition is that you need C++ 20 or higher, or use a compiler that has the feature __cpp_lib_bit_cast, as shown in feature-testing.

If you are using a modern GCC or VS2022, this will simply be transparent for you and constexpr-initialization from built-in double will simply just work.

This is all cycling in #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants