2

On page 3/7 of the fp package we see the definition of the inverse sine function as below:

\FParcsin#1#2 % #1 := arcsin(#2)

From high school we may remember: Arcsin(0.5)=pi/6= 0.524 around. I got 0 for Arcsin(0.5) using fp package. Which is strange to me:

\documentclass{article}

\usepackage{fp}

\begin{document} \FPdiv\pidivsix \FPpi 6 \FParcsin \arcsinhalf 0.5 \ \FParcsin \arcsinone 1 Arcsin$(1)=\arcsinone$.\ Arcsin$(\frac{1}{2})=\arcsinhalf$.\ This is a wrong answer the correct value is $\pidivsix$.

\end{document}

enter image description here

epR8GaYuh
  • 2,432
Aria
  • 1,523
  • I'm no TeX specialist, but it seems to me that here, \frac{1}{2} is not interpreted as a number, but as a string. A TeX specialist can explain this better than I can. – AndréC Aug 10 '20 at 05:02
  • I used frac 1 2 as a text to type and did not deal with it as a number. – Aria Aug 10 '20 at 05:12
  • 5
    Try \FParcsin \arcsinhalf{0.5}. Otherwise your input is \FParcsin \arcsinhalf{0} and you are typesetting .5 – cgnieder Aug 10 '20 at 05:16
  • 5
    Replace \FParcsin \arcsinhalf 0.5 \\ with \FParcsin \arcsinhalf {0.5}. Apparently fp grabs the numbers like normal arguments. If you omit the braces, you only get 0. You can already see that something fishy is going on on the input stage from the fact that the document typesets a spurious '.5'. – moewe Aug 10 '20 at 05:18
  • @cgnieder you gave me the correct answer. Would you write your answer below in the answer section then I accept it. – Aria Aug 10 '20 at 05:23
  • 1
    @Aria Indeed, you are right. – AndréC Aug 10 '20 at 05:23
  • Also, you might want to use $\arcsin(\frac{1}{2})=...$ instead of Arcsin$(\frac{1}{2})=...$. – Skillmon Aug 10 '20 at 07:29

1 Answers1

3

TeX will interpret a string of digits (with optional sign and optional decimal point or comma) as a decimal number only if it has to, that is

when it is looking for an explicit dimension, in which case the string representing a decimal number must be followed by one of the allowed units.

It's quite unfortunate that the documentation of fp presents the syntax in the shown form, because it might suggest resemblance to other programming languages that are more forgiving when numbers are involved.

Since TeX is mainly a typesetting program, it doesn't scan numbers except when it has to, but this can only happen when primitive commands are used, not with defined macros such as \FParcsin.

The suggestion \FParcsin#1#2 means that #1 and #2 are standard arguments that therefore should be braced (unless they consist of a single token). So

\FParcsin{\arcsinhalf}{0.5}

is the correct syntax. This can be abbreviated into \FParcsin\arcsinhalf{0.5} because the first argument is a single token.

You could safely type \FParcsin\arcsinone1, but it's better to stick to a standard and type \FParcsin\arcsinone{1}, so the arguments are also visually clearer.

Similarly, you should stick to

\FPdiv\pidivsix{\FPpi}{6}

for the same reasons. The code \FPdiv\pidivsix \FPpi 6 works, but if you try to compute pi over 10,

\FPdiv\pidivten \FPpi 10

would definitely not work and should be

\FPdiv\pidivten {\FPpi} {10}

or

\FPdiv\pidivten{\FPpi}{10}

Spaces are ignored when looking for an argument, so you have some freedom to suit your preferences.

egreg
  • 1,121,712