Topic: Standard math calls


Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: Fri, 1 Feb 2002 17:50:48 GMT
Raw View
Is there a standard way in C++ to call mathematical functions like sin(),
cos(), etc.?


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Scott Robert Ladd" <scott@coyotegulch.com>
Date: Fri, 1 Feb 2002 21:19:10 CST
Raw View
"Philippe A. Bouchard" <philippeb@videotron.ca> wrote
> Is there a standard way in C++ to call mathematical functions like sin(),
> cos(), etc.?

C++ includes all of the methematical functions defined in the 1989 C
Standard. You'll find all of these listed in the header files <cmath> or
<math.h>, depending on how your compiler organizes things. Browse those
files, and it should be self-explanatory.

The C++ Standard does not repeat the definitions of these functions; it
assumes you have a copy of Standard C.

--
Scott Robert Ladd
Master of Complexity, Destroyer of Order and Chaos
  Visit CoyoteGulch at http://www.coyotegulch.com
    No ads -- just info, algorithms, and very free code.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: Fri, 1 Feb 2002 22:44:55 CST
Raw View
So it's still depends on C calls:
- float or long double only (not even using templates)
- Haven't tried it yet but it doesn't look to be inlined

complex types, small integers (can be optimized), ... no?

(I won't discuss real mathematics, but it is always in my mind)

"Scott Robert Ladd" <scott@coyotegulch.com> wrote in message
news:sNI68.188187$_w.29538164@typhoon.tampabay.rr.com...
> "Philippe A. Bouchard" <philippeb@videotron.ca> wrote
> > Is there a standard way in C++ to call mathematical functions like
sin(),
> > cos(), etc.?
>
> C++ includes all of the methematical functions defined in the 1989 C
> Standard. You'll find all of these listed in the header files <cmath> or
> <math.h>, depending on how your compiler organizes things. Browse those
> files, and it should be self-explanatory.
>
> The C++ Standard does not repeat the definitions of these functions; it
> assumes you have a copy of Standard C.
>
> --
> Scott Robert Ladd
> Master of Complexity, Destroyer of Order and Chaos
>   Visit CoyoteGulch at http://www.coyotegulch.com
>     No ads -- just info, algorithms, and very free code.
>
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Scott Robert Ladd" <scott@coyotegulch.com>
Date: Sat, 2 Feb 2002 22:50:20 GMT
Raw View
Hi,

> - float or long double only (not even using templates)
The standard *does* specify extensions to C, in the form "float cos(float)"
and "long double cos(long double)" -- but some compiler vendors simply map
these to the double versions of those functions. I've found that the best
way to see what a vendor does is to look in the actual header files.

> - Haven't tried it yet but it doesn't look to be inlined
Some compilers -- INtel C++ and Microsoft Visual C++, for example -- have a
compile-time switch to inline many functions, including the trig and log
functions. Again, this is entirely compiler-dependent.

> complex types, small integers (can be optimized), ... no?
No small integer support -- but the complex<> template does support the
usual battery of functions, including the trig and log functions.

I am informed by members of this group the weak numeric support in Standard
C++ is due to a lack of numerical programmers on the committees. This is one
reason I've moved much of my numeric work to Fortran 95 and C99 (as the
later becomes available).

--
Scott Robert Ladd
Master of Complexity, Destroyer of Order and Chaos
  Visit CoyoteGulch at http://www.coyotegulch.com
    No ads -- just info, algorithms, and very free code.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: Sun, 3 Feb 2002 00:22:42 GMT
Raw View
"Scott Robert Ladd" <scott@coyotegulch.com> wrote in message
news:PBW68.504929$oj3.97788604@typhoon.tampabay.rr.com...
> I am informed by members of this group the weak numeric support in
Standard
> C++ is due to a lack of numerical programmers on the committees. This is
one
> reason I've moved much of my numeric work to Fortran 95 and C99 (as the
> later becomes available).

Yes, and maybe programmers don't know in which way to put an abstraction
effort (is there a lot of people out there using intensive parallel
processing?). At least, little things like variable precision floats going
from financial to scientific algorithms would be usefull.


Thanks,

Philippe A. Bouchard
Xandros Software Engineer


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Mon, 4 Feb 2002 08:07:37 GMT
Raw View
"Philippe A. Bouchard" wrote:
>
> So it's still depends on C calls:
> - float or long double only (not even using templates)
> - Haven't tried it yet but it doesn't look to be inlined
>
> complex types, small integers (can be optimized), ... no?

<complex> defines overloaded versions of these functions that work with
complex numbers.
<cmath> defines float and long-double overloads of all the C standard
library math functions. In addition, it overloads abs() and div() to
accept long arguments.
There's no support yet for smaller integer types.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]