timlg07 / Number.cmd

A new data type for Batch, that can represent large & floating-point numbers and enables calculation with those.
MIT License
2 stars 1 forks source link

Number.cmd should provide formatting options for output numbers. #23

Closed timlg07 closed 3 years ago

timlg07 commented 3 years ago

Possible syntax for output formatting:

Number x = 1 / 3 format:".3"
:: x = 0.333
Number x = 4 / 10 format:"1,2"
:: x = 0,40
Number x = 22 * 23 format:"1.2"
:: x = 5.06E2
timlg07 commented 3 years ago

A more accurate definition of the format syntax:

"x.y" with x being the number of digits before and y the number of digits after the decimal point. The precision in this case is always fixed and defined as: precision = x + y. This definition overwrites a manually given precision. The exponent will be adjusted to meet the format requirements. If the exponent is zero, it is omitted.

"x." with x being the number of digits before the decimal point. In this case, all operations will be performed with default precision. The number of digits after the floating point is not limited and is used for all actual-precision - x remaining digits. In case no digits are leftover, which happens if and only if actual-precision = x, the floating-point is omitted. The exponent will still be adjusted to meet the requirements of the format.

".y" with y being the number of digits after the decimal point. Analogical to the previous case, the default precision behavior is used; all remaining digits will now be placed before the decimal point and the exponent will get adjusted as necessary. The floating-point won't get omitted in any case though: If actual-precision = y a leading 0 followed by the point will be added.

"." does not limit the amount of digits at all. The default precision behavior will be used and the digits will be split so that the exponent is zero and can be omitted completely. => This is the only format, that will never contain an exponent.

If you add a plus sign + as first character of the format string, the sign is always shown, even when it might be redundant. This makes it easier for you to process the output, as you can always expect the first character to be the sign (Even if the result is zero).

Notes:

timlg07 commented 3 years ago

Format parameter parser finished: #32.

timlg07 commented 3 years ago
timlg07 commented 3 years ago

Formatting algorithm implemented: #33

timlg07 commented 3 years ago

Plus sign option implemented: #34 #36

timlg07 commented 3 years ago

Basic automated tests written: #37