fabricedesre / cc3200-rs

Getting Rust to run on a TI cc3200
Mozilla Public License 2.0
7 stars 2 forks source link

Add format_float_into and format_int_into routines written in rust. #42

Closed dhylands closed 7 years ago

dhylands commented 7 years ago

Here's a pair of formatting routines.

If you run the example format_into.rs then I get the following output:

Num: >*****<
Num: >*****<
Num: >12345<
Num: >12345<
Num: > 1234<
Num: >01234<
Num: >  123<
Num: >00123<
Num: >   12<
Num: >00012<
Num: >    1<
Num: >00001<
Num: >    0<
Num: >00000<
Num: >   -1<
Num: >-0001<
Num: >  -12<
Num: >-0012<
Num: > -123<
Num: >-0123<
Num: >-1234<
Num: >-1234<
Num: >*****<
Num: >*****<
Num: >*****<
Num: >*****<
Num: >********<
Num: >12345.68<
Num: > 1234.57<
Num: >  123.46<
Num: >   12.35<
Num: >    1.23<
Num: >    1.00<
Num: >    1.00<
Num: >    0.10<
Num: >    0.00<
Num: >   -0.10<
Num: >   -1.00<
Num: >   -1.00<
Num: >   -1.23<
Num: >  -12.35<
Num: > -123.46<
Num: >-1234.57<
Num: >********<

There are also some tests. I haven't been able to get the tests to work inside this crate, but they worked in a standalone crate.

fabricedesre commented 7 years ago

Looks nice overall! One thing I don't like is the overflow behavior. I would prefer the formatting function to return a bool to notifiy the caller that formatting was not possible. I think that would also let us get rid of the custom cases for when the filler is ' ' or not.

dhylands commented 7 years ago

This changes the routines to return a bool, true = number formatted ok, false = overflow.

In the case of an overflow, the contents of the buffer may be modified, and won't represent the number passed in.

dhylands commented 7 years ago

I also have this in a separate repository so I could run cargo test https://github.com/dhylands/format-rs

If you want, I could link to that, or just leave format.rs in this repo.

fabricedesre commented 7 years ago

lgtm!