New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builtin math shouldn't require a --scale
argument for floating point math.
#4478
Comments
Wow, that's gross. Floating point arithmetic ought to just work. |
Indeed, and I'd say that the scale argument should just go away. People can run |
the
produces what expected. However, if you set default scale for |
@talamus: It's not anymore. In 3.0, it's a builtin. And I don't think we want to add something like "scale". At least not in the way that bc does - without, you can only get integers, and with it, you can't do modulo. |
So, I've tried to just remove trailing zeroes and "." from the string represenation (unfortunately there's no useful standardized format string for this -
However, one issue I have here is that |
What about teaching |
Sure. I'd add one caveat: We always accept "." as the separator, so scripts don't break across locales just because of numeric crap (AFAICT, there is no POSIX way to read a double that isn't locale-dependent). I've added something like that in math, and I just ended up switching LC_NUMERIC temporarily. In (It's possible that fish should just use LC_NUMERIC=C internally always - which would make this much easier) |
Okay, printf explicitly tries the user's locale and then C. |
This changes the behavior of builtin math to floating point by default. If the result of a computation is an integer, then it will be printed as an integer; otherwise it will be printed as a floating point decimal with up to 'scale' digits past the decimal point (default is 6, matching printf). Trailing zeros are trimmed. Values are rounded following printf semantics. Fixes fish-shell#4478
This changes the behavior of builtin math to floating point by default. If the result of a computation is an integer, then it will be printed as an integer; otherwise it will be printed as a floating point decimal with up to 'scale' digits past the decimal point (default is 6, matching printf). Trailing zeros are trimmed. Values are rounded following printf semantics. Fixes fish-shell#4478
The old
math
function wouldn't do this (we cast to an integer in builtin_math.cpp):bc
would print10.5
.The only way to coax out the right answer is to use
--scale
, which I consider something kind of unpleasant from our old math function that was an artifact ofbc
, not something we should want to encourage let alone require. Ideally we could have a nice default where5.0
printed5
and5.0010
printed5.001
(roughly %g without the exponent stuff).The text was updated successfully, but these errors were encountered: