M
Martin McCormick
Most of the C programming I write manipulates strings so I haven't had
much experience with numerical functions and passing variables in and
out which brings me to a laughably simple problem that I am having.
How does one pass two unsigned longs in to a function that
will ultimately do floating point calculations on them?
A C tutorial I have says that one should not declare the
inputs to a function as floats but should use doubles which will
handle other numerical types. An example of what I am trying to do is:
void do_percent (lownum, highnum)
double lownum;
double highnum;
{ /*percentage routine*/
printf ("%.3f\n", (lownum/highnum));
return;
} /*percentage routine*/
There is no percentage arithmetic in it yet because if I call
it like:
do_percent (smallnumber, largenumber); with both the input arguments
being unsigned long numbers, the two values become corrupt when doing a
gdb trace.
If I declare them as unsigned longs in the function, they do
keep their values, but printf outputs garbage values so it obviously
doesn't know what I tried to do.
I simply want to learn good practices for passing numerical
values in to functions so any good ideas are appreciated. I have
obviously misunderstood what I read. Many thanks.
much experience with numerical functions and passing variables in and
out which brings me to a laughably simple problem that I am having.
How does one pass two unsigned longs in to a function that
will ultimately do floating point calculations on them?
A C tutorial I have says that one should not declare the
inputs to a function as floats but should use doubles which will
handle other numerical types. An example of what I am trying to do is:
void do_percent (lownum, highnum)
double lownum;
double highnum;
{ /*percentage routine*/
printf ("%.3f\n", (lownum/highnum));
return;
} /*percentage routine*/
There is no percentage arithmetic in it yet because if I call
it like:
do_percent (smallnumber, largenumber); with both the input arguments
being unsigned long numbers, the two values become corrupt when doing a
gdb trace.
If I declare them as unsigned longs in the function, they do
keep their values, but printf outputs garbage values so it obviously
doesn't know what I tried to do.
I simply want to learn good practices for passing numerical
values in to functions so any good ideas are appreciated. I have
obviously misunderstood what I read. Many thanks.