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

mistake in definition of flnp1 #155

Closed
sanjayjain159 opened this issue Jan 22, 2024 · 5 comments · Fixed by #160
Closed

mistake in definition of flnp1 #155

sanjayjain159 opened this issue Jan 22, 2024 · 5 comments · Fixed by #160

Comments

@sanjayjain159
Copy link

defn given in csrc is flnp1 = lnx + 1, where as it should be flnp1= ln(1+x) and only the math lib function log1p should be used for it. Moreover, the math lib expm1 should also be defined in csrc. Both expm1 and lnp1 are given in x87 assembly instructions snd glibc math lib and dpan. Moreover, the definitions of of sinh, tanh, asinh, atanh, should not be constructed from log (or ln) or exp. Either should be left too user to define or only math lib functions sbould be taken. This is necessary so as not to lose precision when x<<1.

@philburk
Copy link
Owner

Thanks! I found FLNP1 at:

case ID_FP_FLNP1: /* ( -- ) ( F: r1 -- r2 ) */

the definitions of of sinh, tanh, asinh, atanh, should not be constructed from log (or ln) or exp.

Where are you seeing that?

The defaults definitions use that standard libraries.
https://github.com/philburk/pforth/blob/master/csrc/pf_float.h#L29

@sanjayjain159
Copy link
Author

Dear Sir, I am only an engineer, not a programmer. From my limited knowledge, I see references to math functions in 4 files namely, pf_float.h, pf_guts.h, pf_compfp.h, and pfinnrfp.h. I think the difficulty is in the last file pfinnrfo.h Here flnp1 is defined as lnx + 1. Moreover when I run the following in pforth: 1E-6 FLNP1 FS. I get the wrong answer. The correct answer is almost 1E-6 as can be verified on an Android phone using free42 calculator app which is an emulator of hp42s calculator. So I assumed that the program is calculating from the definitions given in pfinnr.h and not using glibc math functions. Pls correct me if I am wrong.

@sanjayjain159
Copy link
Author

Sorry, I accidentally closed the issue. In pfinnrfp.h are also the definitions of asinh etc in terms of glibc math function log (ln).

defn given in csrc is flnp1 = lnx + 1, where as it should be flnp1= ln(1+x) and only the math lib function log1p should be used for it. Moreover, the math lib expm1 should also be defined in csrc. Both expm1 and lnp1 are given in x87 assembly instructions snd glibc math lib and dpan. Moreover, the definitions of of sinh, tanh, asinh, atanh, should not be constructed from log (or ln) or exp. Either should be left too user to define or only math lib functions sbould be taken. This is necessary so as not to lose precision when x<<1.

@sanjayjain159
Copy link
Author

sanjayjain159 commented Jan 26, 2024 via email

philburk added a commit that referenced this issue Mar 28, 2024
Was log(x)+1
Now log(x+1)

Fixes #155
@philburk
Copy link
Owner

The standard for FLNP1 is at: https://forth-standard.org/standard/float/FLNPOne

The C function ln1p is described at: https://man7.org/linux/man-pages/man3/log1p.3.html

I do not see a problem with the definition of asinh, etc. If you still see a problem then open a new bug.

Thanks for reporting this.

philburk added a commit that referenced this issue Mar 28, 2024
Was log(x)+1
Now log(x+1)

Fixes #155
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

Successfully merging a pull request may close this issue.

2 participants