Skip to content

Commit

Permalink
doc: why float can be described using 0x
Browse files Browse the repository at this point in the history
  • Loading branch information
louiscaron authored and DanielT committed Aug 10, 2024
1 parent cd0a5c7 commit e7b3a4e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions a2lfile/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ impl<'a> ParserState<'a> {
pub(crate) fn get_float(&mut self, context: &ParseContext) -> Result<f32, ParserError> {
let token = self.expect_token(context, A2lTokenType::Number)?;
let text = self.get_token_text(token);
// some vendor tools are defining the characteristic UpperLimit and LowerLimit
// (float values from specifications) using 0xNNN for characteristics that
// are actually integers.
if text.starts_with("0x") || text.starts_with("0X") {
match u64::from_str_radix(&text[2..], 16) {
Ok(num) => Ok(num as f32),
Expand All @@ -617,6 +620,9 @@ impl<'a> ParserState<'a> {
pub(crate) fn get_double(&mut self, context: &ParseContext) -> Result<f64, ParserError> {
let token = self.expect_token(context, A2lTokenType::Number)?;
let text = self.get_token_text(token);
// some vendor tools are defining the characteristic UpperLimit and LowerLimit
// (float values from specifications) using 0xNNN for characteristics that
// are actually integers.
if text.starts_with("0x") || text.starts_with("0X") {
match u64::from_str_radix(&text[2..], 16) {
Ok(num) => Ok(num as f64),
Expand Down

0 comments on commit e7b3a4e

Please sign in to comment.