mpmath icon indicating copy to clipboard operation
mpmath copied to clipboard

Unexpected results from elliprj with NaN input

Open jacksonvanover opened this issue 7 years ago • 1 comments

mpmath version: 1.1.0

When the fourth argument to elliprj is a NaN, the result ends up being the product of the first three arguments. While nifty, I don't think this is expected behavior... GSL's implementation of the same function invokes their error handler citing a domain error which feels more appropriate.

Example:

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mpmath import *
>>> import numpy as np
>>> elliprj(1,2,3,4)
mpf('0.23984809974956775')
>>> elliprj(1,2,3,np.nan)
mpf('6.0')
>>> elliprj(1,3,3,np.nan)
mpf('9.0')
>>> elliprj(1,3,4,np.nan)
mpf('12.0')
>>> elliprj(0,1,4,np.nan)
mpf('0.0')

jacksonvanover avatar Nov 06 '19 18:11 jacksonvanover

Looks as a typo for me. Special inputs handled there: https://github.com/mpmath/mpmath/blob/8778568951113dc9f2619e15e57e41593688fea5/mpmath/functions/elliptic.py#L553-L556

This happens with same multiplication as in the RF_calc(): https://github.com/mpmath/mpmath/blob/8778568951113dc9f2619e15e57e41593688fea5/mpmath/functions/elliptic.py#L483-L487

skirpichev avatar Feb 21 '26 02:02 skirpichev