batavia icon indicating copy to clipboard operation
batavia copied to clipboard

Failing macOS unittest - pow corner case(s)

Open pzrq opened this issue 6 years ago • 2 comments

Expected Behavior

# Expected - Python 3.7.3
>>> print(pow(0.7071067811865476+0.7071067811865475j, 18446744073709551616))
(0.5092909260061389+0.8605944182295221j)

Current Behavior

# Batavia (testserver demo - copy/paste and run)
print(pow(0.7071067811865476+0.7071067811865475j, 18446744073709551616))
(0.7531061966369503+0.6578989714135652j)

Steps to reproduce

  1. At a terminal, the test which inspired my issue:
(venv) pzrq@mozzie:~/Projects/beeware/batavia$ python setup.py test -s tests.builtins.test_pow.BuiltinTwoargPowFunctionTests.test_complex_int

Your Environment

  • Python Version (list the specific version number) Python 3.7.3

  • Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)

    • [x] OSX 10.14.6
    • [ ] Linux
    • [ ] Windows
    • [ ] Ubuntu

pzrq avatar Aug 06 '19 07:08 pzrq

I may have the expected/actual backwards (or at least needs more data), in an Ubuntu VM:

pzrq@pzrq-VirtualBox:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04 LTS
Release:	18.04
Codename:	bionic

pzrq@pzrq-VirtualBox:~$ python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(pow(0.7071067811865476+0.7071067811865475j, 18446744073709551616))
(0.7531061966369503+0.6578989714135652j)

pzrq avatar Aug 06 '19 07:08 pzrq

The bug looks to be here:

https://github.com/beeware/batavia/blob/master/batavia/types/Complex.js#L364

If the exponent is larger than 100, we cast it to a JavaScript 52-bit Number, so we lose the lower-order bits.

Instead we should just do the exponentiation ourselves.

swenson avatar Aug 06 '19 15:08 swenson