Sitelet https://web.archive.org/web/20210816153057/https://github.com/OpenRCT2/OpenRCT2/issues/14093
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

User defined literals for Money32 #14093

Open
duncanspumpkin opened this issue Feb 14, 2021 · 1 comment
Open

User defined literals for Money32 #14093

duncanspumpkin opened this issue Feb 14, 2021 · 1 comment

Comments

@duncanspumpkin
Copy link
Contributor

@duncanspumpkin duncanspumpkin commented Feb 14, 2021

We currently use a macro for writing down a money amount as a literal. We should move to a more modern C++ representation with a user defined literal like the below:

constexpr money32 operator"" _GBP(long double money)
{
    return money * 10;
}

static_assert(MONEY(2, 40) == 2.40_GBP);

Go through the codebase and replace all MONEY macro uses with the equivalent version. You might need to also make a helper function that can convert from a runtime value to money as the macro is currently used in one or two places.

@geoff-B
Copy link
Contributor

@geoff-B geoff-B commented Mar 1, 2021 •

I'm interested in taking on this issue, but one quick question: Why does the money have to be multiplied by 10? Doesn't 2.40_GBP simply represent £2.40?

Nevermind, figured it out myself, it's because money32 is stored in multiples of 0.10.

geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
There should be a better way to do this, that would probably require the casting of the number to a long double, then checking it for overflow.
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
One underscore for UDL, not two
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
expression converts runtime values to money, replaces the function of the MONEY macro.
Fixed runtime uses of MONEY that were removed in the initial find and replace
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
Accepting suggestion, will do a proper search and replace later.

Co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
Co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
Is the use of auto correct, or should it be in money32?
I am fairly new to C++, coming from C.
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 1, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 2, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
There should be a better way to do this, that would probably require the casting of the number to a long double, then checking it for overflow.
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
One underscore for UDL, not two
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
expression converts runtime values to money, replaces the function of the MONEY macro.
Fixed runtime uses of MONEY that were removed in the initial find and replace
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
Accepting suggestion, will do a proper search and replace later.

Co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
Is the use of auto correct, or should it be in money32?
I am fairly new to C++, coming from C.
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
Co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 3, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 6, 2021
 Replace old fraction and whole with single int, with overflow check

Co-Authored-By: Duncan <duncan.p.frost@gmail.com>
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 6, 2021
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 6, 2021
Instead of storing whole and decimal separately in MONEY function,
multiply doubles by 10 and cast to int32_t
function is not needed at all for ints
geoff-B added a commit to geoff-B/OpenRCT2 that referenced this issue Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants