c3d / db48x

RPL runtime for the DM42 calculator, in the spirit of HP48/49/50
http://48calc.org
GNU Lesser General Public License v3.0
113 stars 13 forks source link

`atan` returning very large value for input with units #1301

Closed c3d closed 1 week ago

c3d commented 2 weeks ago

Example 2 in E Field Finite Line has the following assignments:

Q=5E-6_C  L=3_m  r=5_cm  εr=1  θ1='atan(L/2/r)' θ2='360_°-θ1'

The assignment for θ1 evaluates as 1 669.92442 34 °.

c3d commented 2 weeks ago

This is apparently related to processing the input unit.

c3d commented 2 weeks ago

The issue is a matter of ordering of unit processing vs. angle processing. Angle processing is tested before unit processing, and this is backwards.

What happens is that we start with an input that is 1.5_m divided by 5_cm. This is 0.3_m/cm. The x->is_real() test for arc-{sin,cos,tan} fails, so we fall through to regular unit processing, and multiply the result by m/cm, which is 100.

This is incorrect: we should multiply the input by that amount.

In any case, we were falling passing 0.3 to ATAN, getting 16.69924 4234 °, then multiplying that result by 100, giving the observed wrong result.

c3d commented 2 weeks ago

Duplicate of #1277, which I had not yet addressed. Marking both as done.