# Issue with fp “missing number” macro

I write an fp macro that calculates the distance between frets on a guitar neck:

\def\ScaleLength{25.5}
\def\ScaleFactor{0.1}

\def\FretDist#1{\FPmul\resulta{-1}{#1}%
\FPdiv\resulta{\resulta}{12}%
\FPpow\resulta{2}{\resulta}%
\FPsub\resulta{1}{\resulta}%
\FPmul\resulta{25.5}{\resulta}
\FPmul\resulta{\resulta}{\ScaleFactor}
\resulta
}


And putting things like

\FretDist{3}


In latex gives the proper floating point value.

When I try to use that value in a package like

\put(3,\FretDist{3}){\circle{3}}


I get an error "Missing number, treated as zero", yet if I do

\put(3,3){\circle{3}}


works fine

-
Please consider assembling your code snippets in a "Minimum Working Example" (MWE) of LaTeX code. –  Mico Mar 15 '12 at 23:09

You can't use \FretDist{3} as argument to \put, because this commands expects a number and not a whole set of instructions to print it. Change the definition of \FretDist as follows

\def\FretDist#1{\FPmul\resulta{-1}{#1}%
\FPdiv\resulta{\resulta}{12}%
\FPpow\resulta{2}{\resulta}%
\FPsub\resulta{1}{\resulta}%
\FPmul\resulta{25.5}{\resulta}
\FPmul\resulta{\resulta}{\ScaleFactor}
}


so that, after calling it, you'll have \resulta available for usage as a number:

\FretDist{3} % store the number in \resulta
\put(3,\resulta){\circle{3}}

-
This works but takes more work when you are looping over a variable. Counters and dimensions cannot be used as arguments for fretdist so I had to use one of fp's registers which means I had to add code to treat it like a counter. –  Uiy Mar 15 '12 at 23:23