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

mixing untyped (negative) floats and integers in arithmetic sometimes drops the sign #1152

Closed
thehowl opened this issue Sep 18, 2023 · 3 comments · Fixed by #1399
Closed
Assignees
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@thehowl
Copy link
Member

thehowl commented Sep 18, 2023

I don't want to investigate precisely what happens right now; in any case, these are some equivalent expressions and their output in gno repl:

println(-3.0 * 1.0 / 2.0) // -1.5
println(-3.0 * 1.0 / 2) // -1.5
println(-3.0 * 1 / 2.0) // -1.5

println(-3 * 1.0 / 2.0) // 1.5
println(-3 * 1.0 / 2) // 1.5
println(-3 * 1 / 2.0) // 1.5

It seems that if a division happens between an untyped bigint and an untyped bigdec, the sign is dropped.

@waymobetta
Copy link
Contributor

Do we mean unsigned here, not untyped?

@thehowl
Copy link
Member Author

thehowl commented Oct 4, 2023

Nope, untyped.

In Go syntax, constant expressions (like "hello", or 2 + 4 -- consider them as any arithmetic/basic operation that doesn't reference a variable) are considered untyped.

That is to say that if we had the variables x, y, z := -3.0, 1.0, 2.0 (the .0 serves to make them "floats"), then x * y / z works fine, because at that point the values are typed into floats, and the expression is handled at the machine level, while an expression like -3 * 1 / 2.0 requires already some handling at the preprocessor level.

@waymobetta
Copy link
Contributor

waymobetta commented Oct 4, 2023

Right, understood. So since there is no declaration, this is where type inference can be incorrect. I was thinking that bigint and bigdec are already typed.

@deelawn deelawn linked a pull request Nov 30, 2023 that will close this issue
7 tasks
@deelawn deelawn self-assigned this Nov 30, 2023
deelawn added a commit that referenced this issue Dec 4, 2023
Addresses #1152 

After debugging for a bit it became apparent the sign was being dropped
during the operation in the `apd` module. Upgrading to the latest
version fixes this.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
gfanton pushed a commit to moul/gno that referenced this issue Jan 18, 2024
Addresses gnolang#1152 

After debugging for a bit it became apparent the sign was being dropped
during the operation in the `apd` module. Upgrading to the latest
version fixes this.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: 🚀 Needed for Launch
Development

Successfully merging a pull request may close this issue.

4 participants