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

Mathematical expression computation bug #361

Closed
button-chen opened this issue May 15, 2024 · 7 comments
Closed

Mathematical expression computation bug #361

button-chen opened this issue May 15, 2024 · 7 comments

Comments

@button-chen
Copy link

Mathematical expression:
(((2871 * 7446 + (4929 - 3435)) / ((754 * 5717) + (13 * 964))) - (6940 * 2554 * 8394 * 6115 * (811 * 4990 * (4305 + 6293))) - (2399 + 2562 + (8560 / 7616) / (2106 * 3816) / (4516 / 9112) - ((4153 * 5871) / 7072 - 6863) * (3101 + 2727 - (4537 * 3626))))

Correct result: -3.90203449761652E+25

anko result: -2.5772796100513167e+18

@button-chen
Copy link
Author

You can use python validation:
Uploading calc.png…

@mattn
Copy link
Owner

mattn commented May 15, 2024

This is different between static typed literal and dynamic typed literal.

See https://go.dev/play/p/FDAs2CW-Arf

@button-chen
Copy link
Author

anko:
env := env.NewEnv()
v, _ := vm.Execute(env, nil, "2/3")

fmt.Println("result: ", v)

output: result: 0.6666666666666666

python:

2/3
0.6666666666666666
2//3
0

So how should anko behave ?

@mattn
Copy link
Owner

mattn commented May 15, 2024

Try below in anko

println((((2871.0*7446.0 + (4929.0 - 3435.0)) / ((754.0 * 5717.0) + (13.0 * 964.0))) - (6940.0 * 2554.0 * 8394.0 * 6115.0 * (811.0 * 4990.0 * (4305.0 + 6293.0))) - (2399.0 + 2562.0 + (8560.0/7616.0)/(2106.0*3816.0)/(4516.0/9112.0) - ((4153.0*5871.0)/7072.0-6863.0)*(3101.0+2727.0-(4537.0*3626.0)))))

@mattn
Copy link
Owner

mattn commented May 15, 2024

(6940.0 * 2554 * 8394 * 6115 * 42888940220)

(6940 * 2554 * 8394 * 6115 * 42888940220)

A part of this 2554 * 8394 * 6115 * 42888940220, this become overflow in int64.

@mattn
Copy link
Owner

mattn commented May 15, 2024

@mattn
Copy link
Owner

mattn commented May 15, 2024

Python can handle large number as bignum. You need to use math/big in Go or Anko.

@mattn mattn closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants