Skip to content
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

math reports negative values as positive when in octal or hex, also mishandles overflow #8417

Closed
ridiculousfish opened this issue Nov 8, 2021 · 8 comments
Assignees
Labels
bug Something that's not working as intended
Milestone

Comments

@ridiculousfish
Copy link
Member

ridiculousfish commented Nov 8, 2021

On fish master commit 1261b53:

> math --base hex -10
0x0
> math --base hex 'pow(2, 40)'
0xffffffff

this is because the value is converted to a (presumably 32 bit) int, and then cast to an unsigned int before it is printed.

@ridiculousfish ridiculousfish self-assigned this Nov 8, 2021
@ridiculousfish ridiculousfish added this to the fish 3.4.0 milestone Nov 8, 2021
@floam
Copy link
Member

floam commented Nov 8, 2021

I think you have this backwards.

@floam
Copy link
Member

floam commented Nov 8, 2021

Current master:

floam@M1 ~> math --base hex -10
0x0
floam@M1 ~> math --base hex 'pow(2, 40)'
0xffffffff
floam@M1 ~> echo $version
3.3.1-573-g3de63f7e2

Because I just fixed it, no? Am I nuts?

@floam
Copy link
Member

floam commented Nov 8, 2021

older versions had the output you are quoting, right?

@floam
Copy link
Member

floam commented Nov 8, 2021

Pulling up the last .app bundle, or an old build from last week:

floam@M1 ~> echo $version
3.3.1
floam@M1 ~> math --base hex 'pow(2, 40)'
0x0
floam@M1 ~> math --base hex -10
0xfffffff6

@ridiculousfish
Copy link
Member Author

Yeah, was testing with the wrong fish. I'll update the issue.

@floam
Copy link
Member

floam commented Nov 8, 2021

Oh gotcha, you actually fixed the output to not be naive, rather than not just totally backwards.

@floam
Copy link
Member

floam commented Nov 8, 2021

Math can always understand its own output regardless of which --base it is running in, this just regressed for negative octal:

> math -0x50 # works
-11
> math -050 # should be -40
-50

@floam
Copy link
Member

floam commented Nov 8, 2021

Nevermind; it was never working/doing that for octal input, negative or positive.

@faho faho added the bug Something that's not working as intended label Nov 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

3 participants