Skip to content

Commit

Permalink
fix handling of negative floats
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed May 16, 2023
1 parent 663d509 commit a114498
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hemtt"
description = "HEMTT - Arma 3 Build Tool"
version = "1.5.0"
version = "1.5.1"
edition = "2021"
license = "GPL-2.0"
authors = ["Brett Mayson <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion book/rhai/library/hemtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The `HEMTT` constant gives access to information and the ability to modify the b
Returns the version of HEMTT.

```js
HEMTT.version().to_string(); // "1.5.0"
HEMTT.version().to_string(); // "1.5.1"
HEMTT.version().major(); // 1
HEMTT.version().minor(); // 4
HEMTT.version().patch(); // 0
Expand Down
2 changes: 1 addition & 1 deletion book/rhai/library/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ debug(HEMTT.project().version.major());
```

```sh
DEBUG [post_release/test.rhai] "1.5.0"
DEBUG [post_release/test.rhai] "1.5.1"
DEBUG [post_release/test.rhai] 1
```

Expand Down
34 changes: 27 additions & 7 deletions libs/config/src/model/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,17 @@ impl Parse for Number {
_ => break,
}
}
if negative {
buffer = -buffer;
}
if decimal_place > 1 {
#[allow(clippy::cast_precision_loss)]
Ok(Self::Float32(
buffer as f32 + decimal as f32 / 10f32.powi(decimal_place - 1),
((decimal as f32 / 10f32.powi(decimal_place - 1)) + buffer as f32)
* if negative { -1f32 } else { 1f32 },
))
} else if buffer > i64::from(i32::MAX) {
Ok(Self::Int64(buffer))
} else if buffer > i64::from(i32::MAX) || buffer < i64::from(i32::MIN) {
Ok(Self::Int64(buffer * if negative { -1 } else { 1 }))
} else {
#[allow(clippy::cast_possible_truncation)]
Ok(Self::Int32(buffer as i32))
Ok(Self::Int32((buffer * if negative { -1 } else { 1 }) as i32))
}
}
}
Expand Down Expand Up @@ -261,6 +259,28 @@ mod tests {
)
.unwrap();
assert_eq!(number, super::Number::Float32(-1_234_567_890.123_456_789));
let mut tokens = hemtt_preprocessor::preprocess_string("-26.55")
.unwrap()
.into_iter()
.peekmore();
let number = super::Number::parse(
&crate::Options::default(),
&mut tokens,
&Token::builtin(None),
)
.unwrap();
assert_eq!(number, super::Number::Float32(-26.55));
let mut tokens = hemtt_preprocessor::preprocess_string("26.55")
.unwrap()
.into_iter()
.peekmore();
let number = super::Number::parse(
&crate::Options::default(),
&mut tokens,
&Token::builtin(None),
)
.unwrap();
assert_eq!(number, super::Number::Float32(26.55));
}

#[test]
Expand Down

0 comments on commit a114498

Please sign in to comment.