Skip to content

Implement Parsing of FloatsΒ #33

@Koloss0

Description

@Koloss0

πŸ—’οΈ Task Description

Summary
Add a feature that lets users type decimal numbers like 2.5 or -1.1 into commands they enter.

Details
Right now, users can only enter integer values in commands. For this issue, add the ability to enter non-integer values (i.e. floats).

To fully implement this feature, you will only need to change three functions: parse_int, get_implied_type, and parse_send.

Here are some starter to-do items:

  • Rename parse_int to parse_number and make the return value anything (because we're parsing any numbers now).
  • In parse_number, detect if the string contains a decimal number. This can be achieved by searching for a dot either at the start, the end, or between two other numbers (e.g. 30., .30 and 30.0).
    • If it is a decimal number, convert the string into its encoded value as a float.
    • If it's not a decimal number, defer to the existing integer detection code.
  • In get_implied_type, accept a string instead and add a check to determine if the string encodes a float
    • If it is a float, return "f32".
  • Lastly, you'll have to appropriately encode the final values as bytes and add them to the data bytearray (in parse_send).

βœ… Completion Criteria

  • The user can easily add decimal numbers to their commands without any bugs or errors.

πŸ“‚ Affected Components

  • Only parser.py should be affected.

🚧 Notes / Reference

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions