473,836 Members | 1,419 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 4105
Mike Wahler wrote:
E. Robert Tisdale wrote:
Christian Bau wrote:
Since I have actually not used the acos() function _once_
in over twenty years of C programming,


So... you're a newbie eh?


I also have been using C for a long time (about 17 years).
I've never used *any* of the 'math.h' functions
in my production code (well, there might be one or two
that I've forgotten about, but you get the idea).
That's because my application domains never needed them.

So am I a 'newbie' too?


To numerical computing evidently.

Nov 14 '05 #31
Mac
On Thu, 26 Feb 2004 01:20:32 +0000, Nick Landsberg wrote:


E. Robert Tisdale wrote:
Nick Landsberg wrote:

[snip]
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. "]


For whatever reason, E. Robert Tisdale modifies posts he is replying to on
occasion. Tisdale has not, to my knowledge, offered any explicit
explanation for this behavior.
-Mac

Nov 14 '05 #32

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:40******** ******@jpl.nasa .gov...
Mike Wahler wrote:
E. Robert Tisdale wrote:
Christian Bau wrote:

Since I have actually not used the acos() function _once_
in over twenty years of C programming,

So... you're a newbie eh?
I also have been using C for a long time (about 17 years).
I've never used *any* of the 'math.h' functions
in my production code (well, there might be one or two
that I've forgotten about, but you get the idea).
That's because my application domains never needed them.

So am I a 'newbie' too?


To numerical computing evidently.


Well, yes, but so what? Numerical computing is only one
of a virtually limitless number of domains in which
C is used. Accounting/business/database applications have been
putting bread on my table for decades.

Here's what I was responding to:

Christian Bau wrote:
Since I have actually not used the acos() function _once_
in over twenty years of C programming,
You replied:
So... you're a newbie eh?


The only conclusion I could draw from context was that you're
calling Christian a 'newbie' with C. IMO this newsgroup's
archives provide much evidence to the contrary.

-Mike
Nov 14 '05 #33
Mac wrote:
For whatever reason,
E. Robert Tisdale modifies posts he is replying to on occasion.
Tisdale has not, to my knowledge,
offered any explicit explanation for this behavior.


What's to explain?
There is no need to quote and it is discouraged.
It is as evil as top posting.
I fix capitalization, punctuation, spelling and grammar errors
to reflect my understanding of what was said.
I am pretty sure that Nick Landsberg meant interpolation
when he said extrapolation and that he meant Dave Rudolf
when he said OP.

I also quietly fix style and programming errors in other people's code
if they aren't essential to understanding the point in question.

Nov 14 '05 #34
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 :-)

Nov 14 '05 #35
"E. Robert Tisdale" wrote:
Mac wrote:
For whatever reason,
E. Robert Tisdale modifies posts he is replying to on occasion.
Tisdale has not, to my knowledge,
offered any explicit explanation for this behavior.


What's to explain?
There is no need to quote and it is discouraged.
It is as evil as top posting.
I fix capitalization, punctuation, spelling and grammar errors
to reflect my understanding of what was said.
I am pretty sure that Nick Landsberg meant interpolation
when he said extrapolation and that he meant Dave Rudolf
when he said OP.

I also quietly fix style and programming errors in other people's code
if they aren't essential to understanding the point in question.


No, you misquote in order to impose your own misunderstandin gs.
If you have some different understanding, write what that is. We
can then be amused at the prattling of children, rather than
outraged.

--
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 #36
In article <40************ **@jpl.nasa.gov >,
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote:
Christian Bau wrote:
The fastest approach would be to split the argument range into two
parts, abs(x) <= c and abs(x) >= c for some suitably chosen c,
probably somewhere around 0.7 or 0.8. For abs (x) <= c, approximate acos
x by a polynomial of the form (pi - ax - bx^3 - cx^5...). For x > c,
define f(z) = acos(1 - z^2). Approximate f(z) by a polynomial of the
form ax + bx^3 + cx^5 + dx^7. Calculate acos(x) = f(sqrt(1 - x)).
For x < -c use acos(x) = pi() - acos(-x) = pi() - f(sqrt(1 + x)).
Take a higher polynomial depending on how much precision you want.
Finding the coefficients is left as an exercise to the reader :)

The substitution z = sqrt(1-x) nicely catches the behavior of acos x
for abs(x) close to 1, where the first derivative is unbounded
and avoids excessive rounding errors.


Have you every implemented and tested this "algorithm" ?
If so please publish it here so that we can "benchmark" it
against our C library implementations of acos. I'll bet you $1.00 that
I can find one that beats your implementation.


Just recently I read something about the typical troll's methods: Demand
documentation, references, everything from others. Always refuse to
provide the same yourself.

So you ask me to invest considerable amount of time to implement an
algorithm for acos, then you do a web search, and all for one dollar?
Asshole.

Lets do it the other way round: You publish ANY implementation of acos
in C, and I bet you UK?20,000 that I can beat it. I have a Macintosh at
home, so we will run speed tests on a PowerPC with a Macintosh G4, using
CodeWarrior 7 for MacOS as the compiler. 64 bit double precision, error
less than 1ulp for the whole range are required, so the only thing to be
measured is speed.

Twenthy thousand pounds makes it worth my while, hurts you enough, and I
am quite confident that I can beat anything you can find.
Nov 14 '05 #37
In article <40************ **@jpl.nasa.gov >,
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote:
Christian Bau wrote:
If you read an article about the Dolph-Chebychev window function,
the first thing that you see is that Chebychev functions
are defined as cos (n*acos(x)) - and they are easily calculated
using a trivial recursion formula that doesn't need anything
more complicated than adding and multiplying.


Please show us the formula.


Google for "Dolph Chebychev". Idiot.
Nov 14 '05 #38
In article <40************ **@jpl.nasa.gov >,
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > 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.


After 20 years, I am still learning. Your posts make you look as if you
stopped learning 30 years ago.

This newsgroup's archives provide much evidence to the contrary.


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


Another typical troll/bully tactics: When called to order, accuse people
of having no sense of humour.
Nov 14 '05 #39
E. Robert Tisdale wrote:
Mac wrote:
For whatever reason,
E. Robert Tisdale modifies posts he is replying to on occasion.
Tisdale has not, to my knowledge,
offered any explicit explanation for this behavior.
What's to explain?
There is no need to quote and it is discouraged.


Appropriate quotation of context is encouraged.
It is as evil as top posting.
No.
I fix capitali[s]ation, punctuation, spelling and grammar errors[.]
I have redacted the above line to fit in with my own personal tastes. Note
that I have used standard editorial notation to mark where changes have
been made. I suggest that, if you must edit quotations, you adopt a similar
strategy.
to reflect my understanding of what was said.
I am pretty sure that Nick Landsberg meant interpolation
when he said extrapolation and that he meant Dave Rudolf
when he said OP.

I also quietly fix style and programming errors in other people's code
if they aren't essential to understanding the point in question.


Even people who are widely recognised to be competent C programmers don't do
this. Your grasp of C has proved to be a little shaky, so it might be wiser
to refrain from introducing what might turn out to be your bugs in what you
claim is other people's code.
--
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 #40

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

Similar topics

0
2303
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
3636
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
3834
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
11903
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
3708
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
3274
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
2936
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
3325
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
4856
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
9816
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
10840
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
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...
0
10254
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...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
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...
1
4448
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
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.