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

Implement SignedFixedDecimal and UnsignedFixedDecimal #5667

Open
wants to merge 131 commits into
base: main
Choose a base branch
from

Conversation

younies
Copy link
Member

@younies younies commented Oct 10, 2024

Related Issues: #5065

@sffc
Copy link
Member

sffc commented Oct 14, 2024

Good start; try to stick with the names we discussed in the thread. FixedDecimal and Signed<FixedDecimal>

@younies younies requested a review from sffc November 13, 2024 23:35
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Good work

Comment on lines +164 to +168
{
let mut num = SignedFixedDecimal::from(related_iso);
num.pad_start(l.to_len() as i16);
num
}
Copy link
Member

Choose a reason for hiding this comment

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

Issue: Why did you change padded_start to pad_start?

However, you'll need the { ... } block anyway if SignedFixedDecimal doesn't duplicate the functions of the inner type. Maybe we can just duplicate the -ed functions.

We discussed the -ed functions in June: #2902 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Because padded_start returns UnsignedFixedDecimal, however, pad_start changes the UnsignedFixedDecimal inside the UnsignedFixedDecimal.

@@ -5,7 +5,7 @@ version = 3
[[package]]
name = "diplomat"
version = "0.8.0"
source = "git+https://github.com/rust-diplomat/diplomat?rev=8744ac97162341f347b63131969ad736e1047f6d#8744ac97162341f347b63131969ad736e1047f6d"
source = "git+https://github.com/rust-diplomat/diplomat?rev=b49d63ec2a50a456b4b6e9d072d3650dca153ff8#b49d63ec2a50a456b4b6e9d072d3650dca153ff8"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Try not to include Cargo.lock changes in PRs with other functional changes. This Cargo.lock file might be stale, but it should be fixed in a standalone PR.

@@ -47,7 +47,7 @@ dependencies = [
[[package]]
name = "diplomat"
version = "0.8.0"
source = "git+https://github.com/rust-diplomat/diplomat?rev=fe5201dd04ee6614942f817b291e90cb01440c19#fe5201dd04ee6614942f817b291e90cb01440c19"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Avoid lockfile diffs

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -19,13 +19,13 @@ use crate::ParseError;
/// nor a sign in the exponent, and behaves differently in pluralization.
#[derive(Debug, Clone, PartialEq)]
pub struct CompactDecimal {
significand: FixedDecimal,
significand: SignedFixedDecimal,
Copy link
Member

Choose a reason for hiding this comment

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

We should eventually make Compact composable, so that you can have an UnsignedCompactDecimal, for example. We can do that later in a different PR.

@@ -3167,10 +2527,6 @@ fn test_from_str_scientific() {
pub output: &'static str,
}
let cases = [
TestCase {
input_str: "-5.4e10",
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Add back some of these cases as failure cases to demonstrate that UnsignedFixedDecimal will fail to parse strings with a minus sign

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, and for the ones starting with + too.

Comment on lines +2512 to +2513
// Check if the output string starts with a plus sign and remove it,
// because we do not show sign for unsigned fixed decimal
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: maybe just reject strings with a + sign in UnsignedRoundingMode. It's okay to be more strict.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I agree with you.

As Rust behavior with unsigned types is as follows:

fn main() {
    let x: u32;
    x = +20;
    println!("x is: {}", x);
}

This results in the following error:

error: leading `+` is not supported
 --> src/main.rs:3:9
  |
3 |     x = +20;
  |         ^ unexpected `+`
  |
help: try removing the `+`
  |
3 -     x = +20;
3 +     x = 20;
  |

@younies younies requested a review from sffc November 19, 2024 01:16
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

LGTM; please sync to the latest main branch

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.

3 participants