473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

namespace check on compile time

Hi,

In the C standard of 1999 additional mathematical functions are added.

For example, beside the traditional
double sin(double x);

there are also the functions:
float sinf(float x);
long double sinl(long double x);

to compute the sin for respectively float and long double types.

However, most compilers do not implement all defined mathematical functions
in the standard. For example, the Intel 7.1 C compiler implements the float
version of sin (sinf), but has not the atan2f function. The gcc compiler
even not implements the sinf function.

It is simple to implement an own function for floats, e.g.

float mysinf(float x) {(float) return sin ((double) x);}

However, it is clear that this typecasted function is less efficient than a
dedicated sinf function. And maybe also not functional equivalent, because I
use a higher precision during the computation. Therefore, I would like to
use the dedicated sinf function if this is implemented by the compiler and
to use my own (not optimal) function otherwise. It is possible to implement
this behaviour by using #ifdef statements, but this is not prefered. In this
way I have to check all the mathematical functions that are used in my
program for every C compiler that can be used to compile my "standard" C
program.

Is it possible to check on compile time the namespace whether a sinf
function is included?
If this is possible, I can define my own sinf function if it is not in the
namespace and otherwise use the dedicated sinf function of the compiler.

Maybe there are also other known solutions to avoid this problem...

Any help is appreciated.

With kind regards,

Lodewijk
Nov 14 '05 #1
4 2391
av
Lodewijk Smit wrote:
Hi,

In the C standard of 1999 additional mathematical functions are added.

For example, beside the traditional
double sin(double x);

there are also the functions:
float sinf(float x);
long double sinl(long double x);

to compute the sin for respectively float and long double types.

However, most compilers do not implement all defined mathematical
functions in the standard. For example, the Intel 7.1 C compiler
implements the float version of sin (sinf), but has not the atan2f
function. The gcc compiler even not implements the sinf function.

It is simple to implement an own function for floats, e.g.

float mysinf(float x) {(float) return sin ((double) x);}

....

Hi,

I think that this is something that is more of a linker issue rather than a
compiler issue. What you can do, is try and link your version of the
function you want to modify after the standard C libraries. This will cause
the standard library function to be picked up in the cases where it is
supported and use your custom function in the case where it is not.

There again like you mentioned, it introduces inconsistencies between the
values that you will get back from different implementations.

If someone else has a better suggestion, I am all eyes (ears won't help in
this case).

A./
Nov 14 '05 #2
Lodewijk Smit wrote:
In the C standard of 1999 additional mathematical functions are added.

However, most compilers do not implement all defined mathematical functions
in the standard. The gcc compiler even not implements the sinf function.
GCC doesn't implement much of the standard library; glibc, however, its
companion, most certainly does implement such -l and -f functions; they
aren't defined unless you're compiling for C99 (or other modes that are
significantly off-topic), which is not the default.
Is it possible to check on compile time the namespace whether a sinf
function is included?


Sort of: you can compare __STDC_VERSION__ against 199901; it's not your
problem if the implementation lies about its conformance status.

--
++acr@,ka"
Nov 14 '05 #3
in comp.lang.c i read:
Lodewijk Smit wrote:
In the C standard of 1999 additional mathematical functions are added. However, most compilers do not implement all defined mathematical functions
in the standard.
then those compilers don't conform for a hosted implementation. a free-
standing implementation need not implement them. whether a specific
compiler claims conformance as hosted and/or free-standing isn't topical
for this newsgroup.
Is it possible to check on compile time the namespace whether a sinf
function is included?


Sort of: you can compare __STDC_VERSION__ against 199901; it's not your
problem if the implementation lies about its conformance status.


a conforming c89 compiler is free to define __STDC_VERSION__ to anything it
likes. qoi alone would argue that you won't find it set to anything too
odd, but it might easily be a value larger than 199901L or non-numeric.

--
a signature
Nov 14 '05 #4
those who know me have no need of my name <no****************@usa.net> writes:
[...]
a conforming c89 compiler is free to define __STDC_VERSION__ to anything it
likes. qoi alone would argue that you won't find it set to anything too
odd, but it might easily be a value larger than 199901L or non-numeric.


Theoretically, yes, but I seriously doubt that any conforming C89/C90
compiler ever has, or ever will, define __STDC_VERSION__ either as
anything larger than 199901L or as anything non-numeric. (Any
compiler that did so would qualify for immediate defenestration.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #5

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

Similar topics

4
by: Teddy | last post by:
If I use just a STL container such as std::vector in my program. Is "using std::vector;" better than "using namespace std" ? Does "using namespace std" cost ?
6
by: Julia | last post by:
How do i get the namespace of a class at compile time? Thanks
29
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using...
29
by: Tiraman | last post by:
Hi, I Build my own dll with my own namespace name and i would like to put it in one place but for the project bin folder so all of the projects will be able to use it . i tried to put the dll...
4
by: John Smith | last post by:
Hi I'm porting some C++ code to new platforms and have some 1-byte aligned structures which need a specific size. Since datatypes can vary on different platforms (which I found out the hard way...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
12
by: bgeneto | last post by:
I know that it's a very basic question, but I can't figure out or find an answer to why do we have to specify a namespace, like this #include<string> using namespace std; when using the...
7
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi all, Since I am always confusing this, I want to know once and for all what is the right way of doing this. I've noticed that some programs use: std::cout<< "yadayada"<<endl;
3
by: tshad | last post by:
I have a file that I converted from VB.Net to C# that works fine in VB.Net when I compile but not in C# using the same libraries. The error I am getting is: PageInit.cs(9,7): error CS0138: A...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.