473,899 Members | 2,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Efficiency of math.h

Hi all,

Normally, I would trust that the ANSI libraries are written to be as
efficient as possible, but I have an application in which the majority of
the run time is calling the acos(...) method. So now I start to wonder how
that method, and others in the math.h library, are implemented.
Dave
Nov 14 '05
92 4141
Nick Landsberg wrote:


E. Robert Tisdale wrote:
Nick Landsberg wrote:
I think the point of Christian's posting was that
he would like more information from the [Dave Rudolf]
[about] why the acos() function was called so often.
If it is something that requires high precision
and MUST be called often
(as in a signal processing application),
then it is one thing.

If it does not require high precision
or [high precision] is used gratuitously,
there might be better ways to accomplish the same thing.
As one poster pointed out, a rough [interpolation]
between values in a static array may satisfy the requirement.
Without knowing the degree of precision needed,
we just don't know.


[You misunderstood at least one part in your paraphrase
of my post. In the second paragraph I meant ...
"If it does not require high precision or *acos()* is
used gratuitiouly, ..." not, as you have interpreted it.
But, re-reading it, I can see how the sentence
could be so interpreted. I also did not put []'s
around the word "interpolation. "]


The [] thing is fairly standard notation for "editorial modification made
here".

In fact, I rattled off an article suggesting Mr Tisdale (if he insists on
editing people's stuff) should start to use such notation, before noticing
(by reading your article) that he has in fact done so.

What he is doing may be stupid, but it's not actually misleading, provided
he marks it appropriately (as he appears to be doing). The point of marking
his editorialisatio ns is that those who distrust them can go back and check
what the original actually said. Unmarked editorialisatio ns are more
insidious. Basically, if you trust a poster not to make unmarked
editorialisatio ns, then okay, you trust them. If you don't, then the
editorial markers probably don't do much for you anyway. But reputable
editors will use them when it is appropriate.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #41
In article <40**********@j pl.nasa.gov> E.************* *@jpl.nasa.gov writes:
Dik T. Winter wrote:
OK, the Tschebyshev approximation in the above case:
double dc[] = {-0.1666666666666 6662966,
0.0083333333333 3094971,
-0.0001984126983 6759707,
0.0000027557316 1030613,
-0.0000000250511 3193827,
0.0000000001591 8135277};
The algorithm reads (y = x*x):
sin = ((((((dc[5] * y + dc[4]) * y + dc[3]) * y + dc[2]) * y + dc[1]) * y
+ dc[0]) * y + 1.0) * x;
(Actually this is for x in [-pi/2, pi/2] with a relative precision of about
1 ULP, or, in tangible terms, the relative error is bounded by about 2e-16.)
That's only about 4 or 5 decimal digits. You will probably find that
your algorithm would benefit from a "range reduction".


Since when is 2e-16 relative error only about 4 or 5 decimal digits? I
would have thought 15+ *decimal* digits... Or do you noe know what
2e-16 means? And in what way do you suggest to do the range reduction?
Anyway, Have you tried to "benchmark" your implementation
against the sin(x) function in your standard C library.
What do you think? Not with regards to time, but with regards to
precision.
If so, please report your results
including the architecture and operating system
where you ran the benchmarks.


Sun Solaris, relative error bounded by about 2e-16.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #42
> Since when is 2e-16 relative error only about 4 or 5 decimal digits? I
would have thought 15+ *decimal* digits... Or do you noe know what
2e-16 means? And in what way do you suggest to do the range reduction?


He might have confused 2e-16 with 2^(-16) ?
Nov 14 '05 #43

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:40******** ******@jpl.nasa .gov...
Nick Landsberg wrote:
I think the point of Christian's posting was that
he would like more information from the [Dave Rudolf]
[about] why the acos() function was called so often.
If it is something that requires high precision
and MUST be called often
(as in a signal processing application),
then it is one thing.

If it does not require high precision
or [high precision] is used gratuitously,
there might be better ways to accomplish the same thing.
As one poster pointed out, a rough [interpolation]
between values in a static array may satisfy the requirement.
Without knowing the degree of precision needed,
we just don't know.


Unfortunately,
I don't know what degree of precision is required either.
We can only hope that Dave Rudolf is still following this thread
and will reply with the answer.


Ya, I'm back. The signal-to-noise ratio in this thread is getting pretty
small :). In short, I don't know the exact accuracy that will be needed. I
am using the acos function do determine the angle between vectors, in order
to simulate angular spring torque in a numeric sumulation of elastic
surfaces. It's for non-scientific graphical simulation, and we do not have a
theoretically rigid physical model, so we can probably get away with some
approximation.

At any rate, I now have a number of avenues to explore. Thank you all for
your ideas.

Dave
Nov 14 '05 #44
E. Robert Tisdale wrote:
Mike Wahler wrote:
The only conclusion I could draw from context was that you're calling
Christian a 'newbie' with C.

Yes. At 20 years, he is just getting started.
This newsgroup's archives provide much evidence to the contrary.

Get a life Mike. And a sense of humor to make it bearable :-)


Mr. E. Tisdale,

I have over 20 years experience with the C language and have
purposely avoided the math library. Most of the embedded systems
I worked would die (come to a hault) or worse if the math
library was included. But, from reading your past posts,
you either claim that embedded systems don't exist or
insuate that only desktop and the like exist.

In smaller embbeded applications, either a lookup table
is used (due to size and speed) or the numerical base
is changed so floating point is not required. Many
times, the accuracy is not required to move a solenoid.

I have learned calculus and numerical analysis. Just
because I don't use all the features of the language
doesn't make me a newbie.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #45
In <c1*********@or avannahka.helsi nki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Dave Rudolf <nu************ ****@hotmail.co m> scribbled the following:
Hi all,

Normally, I would trust that the ANSI libraries are written to be as
efficient as possible, but I have an application in which the majority of
the run time is calling the acos(...) method. So now I start to wonder how
that method, and others in the math.h library, are implemented.


This depends completely on the C compiler used and is not standardised.


It is entirely a library issue and need not depend at all on the C
compiler being used. I have seen assembly-only implementations of
<math.h>.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #46
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:40******** ******@jpl.nasa .gov...
Mike Wahler wrote:
The only conclusion I could draw from context was that
you're calling Christian a 'newbie' with C.
Yes. At 20 years, he is just getting started.
This newsgroup's archives provide much evidence to the contrary.


Get a life Mike.


I'm quite happy with my life, but thanks for your concern.
And a sense of humor to make it bearable :-)


I'm also quite satisfied with my sense of humor (some
folks often ask me to 'tone it down'. :-)

Ya know, I should probably just plonk you, but you're
just too darn amusing. :-)

-Mike
Nov 14 '05 #47
Thomas Matthews wrote:
I have over 20 years experience with the C language
and have purposely avoided the math library.
Most of the embedded systems I worked would die (come to a hault)
You probably meant halt.
or worse if the math library was included.
Why?
But, from reading your past posts, you either claim that
embedded systems don't exist or insuate
You probably meant insinuate.
that only desktop and the like exist.
Not that I recall.
Can you quote such an instance?
In smaller embbeded
You probably meant embedded.
applications, either a lookup table is used
(due to size and speed) or the numerical base is changed
so [that] floating point is not required. Many times,
the accuracy is not required to move a solenoid.

I have learned calculus and numerical analysis.
Just because I don't use all the features of the language
doesn't make me a newbie.


No.
You're a newbie because you have only 20 years experience.

Nov 14 '05 #48
Mike Wahler wrote:
E. Robert Tisdale:
Mike Wahler wrote:
The only conclusion I could draw from context was that
you're calling Christian a 'newbie' with C.
Yes. At 20 years, he is just getting started.
This newsgroup's archives provide much evidence to the contrary.


Get a life Mike.


I'm quite happy with my life, but thanks for your concern.
And a sense of humor to make it bearable :-)

I'm also quite satisfied with my sense of humor


It's perverse.
(some folks often ask me to 'tone it down'. :-)

Ya know, I should probably just plonk you,
Not likely. Trolls never use kill files.
Their egos won't let them. They just threaten.
but you're just too darn amusing. :-)


Yes, everyone knows that you troll for fun.

Nov 14 '05 #49
Mike Wahler wrote:
<E.************ **@jpl.nasa.gov > wrote:
.... snip ...
And a sense of humor to make it bearable :-)


I'm also quite satisfied with my sense of humor (some
folks often ask me to 'tone it down'. :-)

Ya know, I should probably just plonk you, but you're
just too darn amusing. :-)


You also need to watch your back with Trollsdale around. ;-[

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2305
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** Invalid arguments to divll. at test_eng/Testout.pm line 30. ...propagated at t/polyser.t line 9. t/polyser.....dubious
17
3639
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels deep. In that case you need much more ram than a PC has to store functions calculated in loops so that you do not have to recalculate every time you cycle through the nest of loops. Using a HD for storage to extend ram is much too slow for many...
9
3838
by: travisperkins03 | last post by:
Hi, I have read somewhere that C code sometimes cannot be compiled to be as efficient as FORTRAN, eg for matrix multiplication, because a C compiler cannot make the assumptions about arrays that a FORTRAN compiler can. But I don't understand the example, not least because I don't understand FORTRAN. I also don't understand why it is more efficient in this case for a compiler to choose the order of evaluation (or whatever it is that it...
335
11990
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
83
3729
by: Licheng Fang | last post by:
Hi, I'm learning STL and I wrote some simple code to compare the efficiency of python and STL. //C++ #include <iostream> #include <string> #include <vector> #include <set> #include <algorithm> using namespace std;
77
3297
by: Aman JIANG | last post by:
THE GAME : Write a C function to swap the bits of a char so that its bits would become the mirror image of the char.MSBs become its LSBs etc. E.g. 11001100 binary would become 00110011 binary. ---------------------------------------
19
2939
by: vamshi | last post by:
Hi all, This is a question about the efficiency of the code. a :- int i; for( i = 0; i < 20; i++ ) printf("%d",i); b:- int i = 10;
9
3330
by: OldBirdman | last post by:
Efficiency I've never stumbled on any discussion of efficiency of various methods of coding, although I have found posts on various forums where individuals were concerned with efficiency. I'm not concerned when dealing with user typing, but I am if a procedure is called by a query. Does the VBA compiler generate "in-line" code for some apparent function calls? For example, y = Abs(x) might be compiled as y = x & mask. The string...
43
4865
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10866
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5891
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6082
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4301
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.