cc-tweaked / CC-Tweaked

Just another ComputerCraft fork
https://tweaked.cc
940 stars 211 forks source link

`atan2` works incorrectly #1962

Closed Renegatto closed 2 months ago

Renegatto commented 2 months ago

Minecraft Version

1.20.1

Version

1.113.0

Details

atan2 returns incorrect results, different from a results of a standalone lua (and from online calculators).

Expected behavior

Checked with my local lua v5.3.6 and in online caluclators, all agree with this:

atan2(0.72999052539834, -0.68345726481518) -- returns 2.3232845658174

Actual behavior

While in CC: Tweaked I get this:

atan2(0.72999052539834, -0.68345726481518) -- returns 0.63057157635225
SquidDev commented 2 months ago

Thanks for the report. I'm afraid I'm not able to reproduce this at all — I get the same result as expected.

image

This is very odd, as CC's Lua VM just uses Java's built-in atan2 implementation, so you'd expect this to be correct! Would you be able to upload your logs? Just in case you're running an odd JVM version or something.

Hex4dec commented 2 months ago

You called atan, not atan2: (from qalc)

> atan(0.72999052539834, -0.68345726481518)

  warning: Additional arguments for function arctan() were ignored. Function can only use 1 argument.
  arctan(0.72999052539834) ≈ 0.6305715764

Lua ignores excessive arguments.

Renegatto commented 2 months ago

You called atan, not atan2: (from qalc)

> atan(0.72999052539834, -0.68345726481518)

  warning: Additional arguments for function arctan() were ignored. Function can only use 1 argument.
  arctan(0.72999052539834) ≈ 0.6305715764

Lua ignores excessive arguments.

You are right, that was atan in both cases, not atan2. I've missed the fact that Lua 5.3 transition

math.atan2 -> math.atan

is not supported in CC:Tweaked.

Anyway, there is no bug, thanks! :+1: