Skip to content

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