Skip to content

Add macros for constructing Decimals from literals #71

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jules-Bertholet
Copy link
Contributor

Adds three macros, d32, d64, and d128, for constructing Decimals from literals.

@benesch
Copy link
Contributor

benesch commented Feb 22, 2022

The idea of a macro for decimal literals seems sound, but I have some questions about the usability and naming:

  • d32, d64, and d128 match the names of the built-in float/integer types, but are at odds with the names of the types in this package (Decimal32, Decimal64, Decimal128). I think it'd be better to follow this package's names and use decimal32, decimal64, and decimal128 as the names of the macros.
  • The inclusion of the N parameter in dec is pretty rough. dec!(13, 1.0) is not super obvious syntax.

Here's an alternate proposal for consideration: we add a single macro named dec with the following usage options:

# Implicit conversion.
let d: Decimal32 = dec!(1.2);
let d: Decimal64 = dec!(1.2);
let d: Decimal128 = dec!(1.2);
let d: Decimal<13> = dec!(1.2);

# Explicit typing, mirroring the built-in integer literal suffixes.
let d = dec!(1.2_decimal32);
let d = dec!(1.2_decimal64);
let d = dec!(1.2_decimal128);
let d = dec!(1.2_decimal<13>);

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

Successfully merging this pull request may close these issues.

2 participants