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

In place type change results in inaccurate math results #1607

Closed
barryple opened this issue Apr 22, 2024 · 5 comments
Closed

In place type change results in inaccurate math results #1607

barryple opened this issue Apr 22, 2024 · 5 comments
Assignees
Labels
bug Something isn't working :integer open discussion Open discussion about features/ideas/suggestions

Comments

@barryple
Copy link

Converting a floating point number to an integer and then adding it to a negative number gives incorrect results.

$> x: 1.1

$> to :integer x + neg(3)
=> -1

results should be
$> 1 + neg(3)
=> -2

I'm running the Linux arm64 mini version v/0.9.83 @ 2023-02-10T16:02:07-05:00 from the download page.

@barryple barryple added the bug Something isn't working label Apr 22, 2024
Copy link

Thank you for submitting an issue! :)

@drkameleon
Copy link
Collaborator

drkameleon commented Apr 22, 2024

First of all, hi!
And welcome to our community! 😉

What you mention seems ... suspicious, so I tried to test it for myself.
And apparently, you are 100% right.

That's exactly what the returned results are.

However, I tried the exact same thing in Ruby and it seems like the result (for this type of operation) is identical, so... I'd have to investigate and see what the best practice should be in this sort of cases... 🤔

Have a look:

Screenshot 2024-04-22 at 16 35 22

Now, that being said, if you want to get the result you mentioned (-2), I'd use round first - that is before converting to :integer.

Here's an example:

Screenshot 2024-04-22 at 16 34 34

I believe this does the trick! 😉

@drkameleon drkameleon added open discussion Open discussion about features/ideas/suggestions :integer labels Apr 22, 2024
@barryple
Copy link
Author

Thanks for the quick response, what I think is a bug, which is now somewhat in doubt because of the same result in ruby :) was easy to work around. In this particular case I didn't want to round but your example taught me something.
thanks!

@drkameleon
Copy link
Collaborator

drkameleon commented Apr 22, 2024

The truth is... the second I saw your result I was like a) the version is not up-to-date (btw, if you want to get the real cutting-edge versions, you could have a look into this - at the bottom: https://github.com/arturo-lang/arturo/actions/runs/8721035508 - there are a few yet-undocumented changes, but I think it's worth the fuss), b) this is a bug with the arm64 architecture, c) this is the end of the world... lol

Generally, I try to keep things as standard as possible, so having a look at how our "competitors" do it (not that it's the absolute rule) is a way to see whether we are too ... off.

In any case, this one is an interesting one that I'll have to investigate further...
So, thanks a lot for mentioning it! 😄

Don't hesitate to post anything else you may come across - be it a real bug, or not, it's always valuable!

Also, you are very welcome to join our Discord server: https://discord.com/invite/YdVK2CB (anything posted there will usually get a reply fast 😉)

@RickBarretto
Copy link
Collaborator

As @drkameleon said, welcome to our community @barryple. Sorry for replying this now, I just notice right now the why of the confusion, and I'm closing this issue.


I already have read this, but re-reading some issues I decided to close it.
This is not a bug. The main issue here is not the round or the conversion to :integer itself, but the precedence.

Arturo's precedence is from right to left, so what you need it not the round function, but just replace the precedence.

Let's take this Python example:
image

Now, let's see what is happening in Arturo:
image

The stack process:

1. []
2. [3]
3. [3 neg]
4. [(-3)]
5. [(-3) + (to :integer x)]
6. [(-3) + 1]
7. [-2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working :integer open discussion Open discussion about features/ideas/suggestions
Projects
None yet
Development

No branches or pull requests

3 participants