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

cmath.log() should take one or two arguments according to Toolbox, but can only take one argument #2258

Open
mobluse opened this issue Oct 31, 2024 · 4 comments
Assignees

Comments

@mobluse
Copy link

mobluse commented Oct 31, 2024

Describe the bug

cmath.log() should take one or two arguments according to Toolbox. Ordinary math.log() can take two arguments.

import cmath
cmath.log(2+3j,10)
  Last command
TypeError: function takes 1 positional arguments but 2 were given

A workaround is to define a new function:
def log(z,a):return cmath.log(z)/cmath.log(a)
and that worked for log(z,a).
cmath.log=log
could not be used to add the new version of the function to cmath, but that is perhaps normal for this version of MicroPython.

Screenshots

download (3)
download (4)
download (5)

To Reproduce

Steps to reproduce the behavior:

  1. Go to the Python app
  2. Type:
  3. import cmath
  4. cmath.log(2+3j,10)
  5. See error

Expected behavior

It should work as in CPython.

Environment

  • Epsilon version 23.2.1 and 23.2.5
  • The platform(s) on which the problem happens: online simulator (23.2.1) and actual device 23.2.5
@mobluse
Copy link
Author

mobluse commented Nov 1, 2024

A quick way to fix this could be to change the presentation in the Toolbox to
log(z) Logaritm to base e

@fbeleznay
Copy link

I am not sure I understand your comment. According to the Micropython documentation, cmath.log only takes one argument (math.log can indeed take two arguments, but this option is not listed for cmath.log).
Also, about the toolbox. On other graphing calculators (unlike in micropython) log is reserved for base 10 logarithm and ln is reserved for base e logarithm. These two have dedicated buttons on the Numworks, too. This is why there is a general base log option in the toolbox. As an IB high school teacher I would not like to see this changed (but maybe I misunderstood your comment).

@mobluse
Copy link
Author

mobluse commented Nov 6, 2024

You see the menu for cmath above. In that log(z, a) has two arguments, but that doesn't work in practice when using cmath (it works when using math). If you in Python shell select from cmath import * and select log(z, a) from the cmath menu you get log(,) on the command line. If you do e.g. log(2,3) you get an error message. log(2) works. I guess the error is in the menu and not in MicroPython, but MicroPython for NumWorks could change if they want it to fit the menu, otherwise they should change the menu.

In Python shell when you press the key ln you get log() (i.e. log to base e) and when you press log you get log10(); this part works as expected.

@adri1numworks adri1numworks self-assigned this Nov 19, 2024
@adri1numworks
Copy link

I reported this issue internally, we'll correct the description in the toolbox! Thanks

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

3 participants