473,327 Members | 2,007 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,327 software developers and data experts.

C routines for Special Functions

Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?

Here's some links for the interested:

Fortran77
http://iris-lee3.ece.uiuc.edu/~jjin/.../routines.html

Matlab
http://ceta.mit.edu/comp_spec_func/

Much thanks,
JB
Nov 14 '05 #1
26 6073
See the GNU GSL library.
Nov 14 '05 #2
Steven G. Johnson wrote:
See the GNU GSL library.


http://sources.redhat.com/gsl/

Nov 14 '05 #3
In article <92**************************@posting.google.com >,
Joe Blow <jo***********@yahoo.com> wrote:
Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?


Have a look at http://www.netlib.org/cephes/. GSL ties you into a number
of bad design decisions that make it clumsy to use.
Nov 14 '05 #4
Keith A. Lewis wrote:
GSL ties you into a number of bad design decisions
that make it clumsy to use.


Would you care to elaborate?

Nov 14 '05 #5

On Sat, 31 Jan 2004, Joe Blow wrote:

Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?


I did a Google search for
"Computation of Special Functions" C source
and found:
http://www.esg.dees.unict.it/esg/gborzi/mathlib.html
http://www.crbond.com/math.htm

But comp.lang.c is not comp.sources.wanted, so please take this
discussion elsewhere.

HTH,
-Arthur
Nov 14 '05 #6
jo***********@yahoo.com (Joe Blow) wrote in message news:<92**************************@posting.google. com>...
Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?


<SNIP>

Some sources of C code for special functions, the first two being the
most important, are

C Mathematical Function Handbook (1992)
by Louis Baker

Atlas for Computing Mathematical Functions: An Illustrated Guide for
Practitioners: With Programs in C and Mathematica (1997)
by William J. Thompson

A Numerical Library in C for Scientists and Engineers (1994)
by H. T. Lau

www.nr.com
Numerical Recipes in C, 2nd Edition (1992)
by Press, Flannery, Teukolsky, and Vetterling
Nov 14 '05 #7
In article <40**************@jpl.nasa.gov>,
E. Robert Tisdale <E.**************@jpl.nasa.gov> wrote:
Keith A. Lewis wrote:
GSL ties you into a number of bad design decisions
that make it clumsy to use.


Would you care to elaborate?


Of course this is just my opinion. I think the GSL group is doing
a great service and since the code is GPL I should really be rolling
up my sleeves and coding instead of complaining. :-)

When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'? It
is perfectly legal, just odd looking and unnecessary. When I was
evaluating this for use in a production library at a large Equity
Derivatives firm a couple of years ago, I kept finding 'odd' things.
Ultimately I chose a Fortran library because GSL was not sufficiently
mature at that time. It has definitely come a long way since then.

If you belive a modern library should be written in C instead of C++,
you can stop reading now. Many of my qualms are due to issues relating
to the gyrations GSL goes to because it does not use C++. I've taken
flak over the years for insisting on writing certain libraries in C (and
even more flak for using Fortran) but I have come to the conclusion that
the small audience that insists on C is, well, small. I'm open to data
indicating otherwise.

Error Handling

I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C. Of course I've had the head
of IT tear me a new asshole when a programmer of mine left an assert
in production code that got called 15 minutes before market open,
so I can't claim to be unbiased.

GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking. I prefer returning NaN's that have embedded error
information. If you don't check the return codes, at least your
program is more likely to return gibberish than to crash.

Vector and Matrix Routines

They do a fine job, but I would love to see something more along
the lines of http://okmij.org/ftp/LinAlg.README.txt. I've tried out
every vector/matix library on the planet, I think, from BLAS and LAPACK
to the compiler busting Blitz++. Simple C++ wrappers for the former seem
to be the best solution for my needs.

General Comments

Excessive use of C macros in source code. Makes the code hard to
understand/fix/maintain.

Not modular. Dependencies between modules should be explicit.

At any rate, that's my 2 cents. Feel free to disagree, it's an internet
newsgroup after all. Comments are welcome.
Nov 14 '05 #8
Dear Joe Blow

Thank you so much for the Fortran Source

Paul

Joe Blow wrote:
Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?

Here's some links for the interested:

Fortran77
http://iris-lee3.ece.uiuc.edu/~jjin/.../routines.html

Matlab
http://ceta.mit.edu/comp_spec_func/

Much thanks,
JB


Nov 14 '05 #9
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message news:<Pi***********************************@unix46 .andrew.cmu.edu>...
But comp.lang.c is not comp.sources.wanted, so please take this
discussion elsewhere.

HTH,
-Arthur

Ahh...blow it out yer arse, Arthur. I suppose
you're trying to deal a lesson in netiquette,
but the fact is that I'm interested in routines
written in the computational language of C, and
even if my fishing cast didn't meet your tight-assed
according-to-Hoyle criterion for a proper post to
this group, it's still obviously close enough. Guys
like you who enforce netiquette like Nazis are usually
the rudest bungholes on the web. Next time a simple
"you may get better information out of the
comp.sources.wanted group" will suffice. There's a
real netiquette lesson for you, Art old boy. Take
your jive netiquette advice elsewhere, ya bloody stickler.

JB
Nov 14 '05 #10
ka*@panix.com (Keith A. Lewis) wrote in message news:<bv**********@panix2.panix.com>...
Have a look at http://www.netlib.org/cephes/. GSL ties you into a number
of bad design decisions that make it clumsy to use.

Thanks for the link Keith...it's pretty useful. In
response to another poster, I am aware of the GSL
software. I avoid it when I can for a variety of reasons,
none of them particularly deep. I'll mention a couple of
things though. I don't like the cumbersome routine names
with gsl_blah_blah tacked onto everything in sight. It
makes for ugly code, in my opinion. Second, they'll have
things like the F-distribution, but no function for the
inverse of the F-distribution. Things like that are annoying...
GSL is incomplete for my purposes. Fortran and Matlab have
many free routines available for the special functions and I
just figured the same thing was out there for C, that's all.

By the way, from my brief perusal of this newsgroup, I must say
I'm stunned that so much time is spent by people bitching about
netiquette (for what seem usually to be rather innocent or trivial
breaches). Must be that programmer mentality at work...

Thanks again Keith,
JB
Nov 14 '05 #11
Keith Lewis wrote:
GSL ties you into a number of bad design decisions
that make it clumsy to use.
.... When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'? It
is perfectly legal, just odd looking and unnecessary.
It would be unnecessary in C++, but not in C.
I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C. Of course I've had the head
of IT tear me a new asshole when a programmer of mine left an assert
in production code that got called 15 minutes before market open,
so I can't claim to be unbiased.

GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking. I prefer returning NaN's that have embedded error
information. If you don't check the return codes, at least your
program is more likely to return gibberish than to crash.


It could be argued that it's better for your program
to crash than to return gibberish, especially if it's
because you haven't bothered to check for errors...

--
Gareth McCaughan
..sig under construc
Nov 14 '05 #12
Keith Lewis wrote:
When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'? It
is perfectly legal, just odd looking and unnecessary.


.... and I replied that in C, as opposed to C++, it is necessary.
That was an error; I apologize. It is unnecessary in C as well
as in C++. However, I don't think it's "odd looking" in C. After
all, when you're declaring but not defining a no-argument function
in C you have to[1] include the "void", so C programmers are
used to seeing no-argument functions with "(void)" for argument list.

[1] If you want the compiler to be able to check that
the function is being used properly, anyway.

--
Gareth McCaughan
..sig under construc
Nov 14 '05 #13
Joe Blow wrote:
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message
But comp.lang.c is not comp.sources.wanted, so please take this
discussion elsewhere.


Ahh...blow it out yer arse, Arthur. I suppose
you're trying to deal a lesson in netiquette,
but the fact is that I'm interested in routines
written in the computational language of C, and
even if my fishing cast didn't meet your tight-assed
according-to-Hoyle criterion for a proper post to
this group, it's still obviously close enough. Guys
like you who enforce netiquette like Nazis are usually
the rudest bungholes on the web. Next time a simple
"you may get better information out of the
comp.sources.wanted group" will suffice. There's a
real netiquette lesson for you, Art old boy. Take
your jive netiquette advice elsewhere, ya bloody stickler.


Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #14
ka*@panix.com (Keith A. Lewis) writes:
Of course this is just my opinion. I think the GSL group is doing
a great service and since the code is GPL I should really be rolling
up my sleeves and coding instead of complaining. :-)

When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'?
It is perfectly legal, just odd looking and unnecessary.
Hmmm, odd looking and unnecessary and ... part of the C standard ;-)
e.g. see ANSI/ISO/IEC 9899:1990 section 5.1.2.2.1 for "int main(void)"
If you belive a modern library should be written in C instead of C++,
you can stop reading now.
Fair enough. It's a GNU project so the main reason we used C is
because of the GNU coding standards (which specify that C be used
where possible). At the time GSL was started (over seven years ago)
C++ techniques such as template metaexpressions and traits were just
being developed. I am still waiting to see a good general numerical
library in C++ however.

(We recommend using C with a very high-level object oriented language
such as Lisp or Python.)
I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I'm not a particular fan of it either, but it is the conventional way
to handle it in C. We worked on a very flexible dynamically-scoped
error context system for a while but it was not popular.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C.
Without the abort() on error default we had many users blithely
ignoring errors and complaining that GSL was producing incorrect
results. So we had to make abort() the default.

It is done with a single configurable gsl_error() function so it can
be changed globally.
GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking.
These should return NaN/Inf for error/overflow conditions (if there
are any that don't, it is bug).
I prefer returning NaN's that have embedded error information.
We have to be portable so this is not really an option for a core
feature (?).
Excessive use of C macros in source code. Makes the code hard to
understand/fix/maintain.
I agree the macros for the implementation of the different types of
vectors and matrices are inelegant. Possibly it would be better to
use a scripting language or m4 to generate the code, rather than cpp.
Not modular. Dependencies between modules should be explicit.
Tried, but turns out to be difficult in practice (originally all
modules were independent) and users seem not particularly interested.

Probably one could write a script to determine the dependencies
automatically, from the source, #includes or the .a file.
At any rate, that's my 2 cents. Feel free to disagree, it's an internet
newsgroup after all. Comments are welcome.


I would say that we did have to make some design decisions, but
hopefully they are not intrinsically bad, just a question of not being
able to please all of the people all of the time.

regards
--
Brian Gough
(GSL Maintainer)

Network Theory Ltd
http://www.network-theory.co.uk/

Nov 14 '05 #15
[f'ups to comp.lang.c]

"Brian Gough" <bj*@network-theory.co.uk> wrote in message
news:87************@debian.local...
ka*@panix.com (Keith A. Lewis) writes:
Of course this is just my opinion. I think the GSL group is doing
a great service and since the code is GPL I should really be rolling
up my sleeves and coding instead of complaining. :-)

When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'?
It is perfectly legal, just odd looking and unnecessary.


Hmmm, odd looking and unnecessary and ... part of the C standard ;-)
e.g. see ANSI/ISO/IEC 9899:1990 section 5.1.2.2.1 for "int main(void)"


More so, C99 has deprecated ()...

6.11.6 Function declarators
The use of function declarators with empty parentheses (not prototype-
format parameter type declarators) is an obsolescent feature.

--
Peter
Nov 14 '05 #16
CBFalconer <cb********@yahoo.com> wrote in message news:<40***************@yahoo.com>...
Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.

Hah! Like I'd ever ask this group anything again. This
newsgroup has been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?
Nov 14 '05 #17
Joe Blow wrote:
CBFalconer <cb********@yahoo.com> wrote in message news:<40***************@yahoo.com>...

Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.


Hah! Like I'd ever ask this group anything again. This
newsgroup has been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?


<OT>

As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?

Best regards,

Sidney

Nov 14 '05 #18
Sidney Cadot <si****@jigsaw.nl> scribbled the following:
Joe Blow wrote:
CBFalconer <cb********@yahoo.com> wrote in message news:<40***************@yahoo.com>...
Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.
Hah! Like I'd ever ask this group anything again. This
newsgroup has been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?

<OT> As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?


Maybe it's the native speaker equivalent of the non-native speaker use
of "u"?
<g, d & r>

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
Nov 14 '05 #19
Sidney Cadot wrote:
Joe Blow wrote:
CBFalconer <cb********@yahoo.com> wrote in message
news:<40***************@yahoo.com>...
Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.


Hah! Like I'd ever ask this group anything again. This newsgroup has
been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?


<OT>

As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?


No. That kind of affectation is normally employed when the
speaker/writer wishes to communicate loss of self-control and the
onset of uncivilized/subhuman behaviors.

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

Nov 14 '05 #20
[Followups set to comp.lang.c]

Keith A. Lewis wrote:

<snip>
Error Handling

I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C. Of course I've had the head
of IT tear me a new asshole when a programmer of mine left an assert
in production code that got called 15 minutes before market open,
so I can't claim to be unbiased.


If the assertion was written properly (i.e. the condition was one that
/must/ be true if the program is correctly written), then the fault lies
not with the programmer who "left an assert in production code" but with
whoever failed to test the condition that led to the assertion being fired.

<snip>

--
Richard Heathfield : bi****@eton.powernet.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 #21
In article <40******@news.rivernet.com.au>,
Peter Nilsson <ai***@acay.com.au> wrote:
[f'ups to comp.lang.c]

"Brian Gough" <bj*@network-theory.co.uk> wrote in message
news:87************@debian.local...
ka*@panix.com (Keith A. Lewis) writes:
> Of course this is just my opinion. I think the GSL group is doing
> a great service and since the code is GPL I should really be rolling
> up my sleeves and coding instead of complaining. :-)
>
> When the first example program in their documentation defines 'int
> main(void) { ... }' you have to wonder a bit. Why the 'void'?
> It is perfectly legal, just odd looking and unnecessary.


Hmmm, odd looking and unnecessary and ... part of the C standard ;-)
e.g. see ANSI/ISO/IEC 9899:1990 section 5.1.2.2.1 for "int main(void)"


More so, C99 has deprecated ()...


I stand (sit actually) corrected.
Nov 14 '05 #22
On Mon, 02 Feb 2004 21:07:54 +0100, in comp.lang.c , Sidney Cadot
<si****@jigsaw.nl> wrote:
<OT>

As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?


no, he's just a prat who can't (or can't be bothered to) spell.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #23
Mark McIntyre wrote:
Sidney Cadot wrote:
As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing,
is that the time where the spelling of "you" changes to "ya",
or is there something deeper that I'm missing?


no, he's just a prat who can't (or can't be bothered to) spell.


No he's just a troll like you. He uses
a troll handle: Joe Blow,
a disposable email address: bl****@yahoo.com,
attempts to provoke an emotional response --
using abusive language in this case.

If you and Joe Blow want to piss all over each other
please move your "discussion" to an appropriate troll newsgroup.
Nov 14 '05 #24
Sidney Cadot <si****@jigsaw.nl> wrote in message news:<bv**********@news.tudelft.nl>...
Joe Blow wrote:
CBFalconer <cb********@yahoo.com> wrote in message news:<40***************@yahoo.com>...

Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.


Hah! Like I'd ever ask this group anything again. This
newsgroup has been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?


<OT>

As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?


No, it's for when you want to make sure that everyone knows
you are an ignorant boor, just in case they missed it in your
earlier behaviour.
Nov 14 '05 #25
In article <bv**********@panix2.panix.com>,
Keith A. Lewis <ka*@panix.com> wrote:
<SNIP>

Error Handling

I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C. Of course I've had the head
of IT tear me a new asshole when a programmer of mine left an assert
in production code that got called 15 minutes before market open,
so I can't claim to be unbiased. If that is about automated buying of shares....
Would you have preferred the program to buy shares with a limit
of $4294967295 ($-1) ?
GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking. I prefer returning NaN's that have embedded error
information. If you don't check the return codes, at least your
program is more likely to return gibberish than to crash.


Which is a bad thing, of course. (I mean returning gibberish.)
The proper thing to do in a real time "show must go on scenario"
(like radar tracking of a missile ms before impact) is to
catch the error and substitute a reasonable value, and hope for
the best. Not to send your defense missile astray.

In the context of mathematical functions I just want to know
that the programmer goofed. If you as a project leader deleted
the programmers assert's you would have a very bad time with me.
If your head of IT agrees with you, I would take my business
elsewhere.

--
Groetjes Albert.
--
Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS
One man-hour to invent,
One man-week to implement,
One lawyer-year to patent.
Nov 14 '05 #26
In article <Hs******************@spenarnc.xs4all.nl>,
Albert van der Horst <al****@spenarnc.xs4all.nl> wrote:
In article <bv**********@panix2.panix.com>,
Keith A. Lewis <ka*@panix.com> wrote:
<SNIP>

Error Handling
....
GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking. I prefer returning NaN's that have embedded error
information. If you don't check the return codes, at least your
program is more likely to return gibberish than to crash.
Which is a bad thing, of course. (I mean returning gibberish.)
The proper thing to do in a real time "show must go on scenario"
(like radar tracking of a missile ms before impact) is to
catch the error and substitute a reasonable value, and hope for
the best. Not to send your defense missile astray.


Any error protocol requires coordination between the library writer
and the library user. People often will simply ignore error codes
no matter how many lectures you deliver on the "proper thing" to do.

My point was that by defalt GSL calls abort on error and provides
no information in the case of "natural form" calling. I'm open
to better solutions than the one I suggested.
In the context of mathematical functions I just want to know
that the programmer goofed. If you as a project leader deleted
the programmers assert's you would have a very bad time with me.
If your head of IT agrees with you, I would take my business
elsewhere.


You sound like the kind of guy I wouldn't hire in the first place.

FWIW, here is an implementation of my proposed error protocol. It is not
portable, but it gives the idea.
/************************************************** ****************************

FILE ensure.h
DATE 2002-10-1
AUTHOR Keith A. Lewis [ka*@kalx.net]
SYNOPSIS

#include "ensure.h"

ensure (expr);
bool ensure_is_error(double);
const char* ensure_message(double);

DESCRIPTION

Simple error protocol using NaNs.

The macro ensure(expr) works much like assert(expr) but
it does not call abort and it can only be used in
functions that return a double. If expr is false, a NaN
is returned. Use ensure_is_error() to detect ensure()
failures and ensure_message() to extract the error
string.

The function ensure_make_nan() embeds a char* into a
NaN. It is your responsibility to make sure that the
argument to ensure_make_nan() exists until
ensure_message() is done using it.

Define USE_ENSURE or _DEBUG before including ensure.h
in order to make ensure does its job. Unlike assert, the
default behavior is to define ensure with an empty
body.

BUGS:

Only works on 32-bit machines.

************************************************** ****************************/
#ifndef ENSURE_H
#define ENSURE_H

#include <math.h>
#include <float.h>

#if defined(_WIN32) && !defined(isnan)
#define isnan _isnan
#endif

#define D_(x) #x
#define S_(x) D_(x)

#if defined(USE_ENSURE) || defined(_DEBUG)

// TODO: offer more flexibility. (no return???)
#define ensure(e) { if (!(e)) \
return ensure_make_nan( \
"file: " __FILE__ \
" line: " S_(__LINE__) \
" error: " #e); }

#else

#define ensure(x)

#endif

// Typedefs and constants

typedef double ensure_error;
const ensure_error ensure_ok = 0;

typedef union {
long l[2];
double d;
} ensure_union;

/* Endian tests */
inline int ensure_lo() { static int i = 1; return *(char*)&i != 1; }
inline int ensure_hi() { static int i = 1; return *(char*)&i == 1; }

/* Equivalent to isnan() function. */
inline bool
ensure_is_error(double x)
{
ensure_union u;

u.d = x;

return u.l[ensure_lo()] == 0x7FFFFFFF || 0 != isnan(x);
}

/* Convert NaN to error message string. */
inline const char*
ensure_message(double x)
{
ensure_union u;

u.d = x;

#pragma warning(push)
#pragma warning(disable: 4312)
return u.l[ensure_lo()] == 0x7FFFFFFF ? (const
char*)u.l[ensure_hi()]
: isnan(x) ? "NaN" : "ensure_message: argument is not a NaN";
#pragma warning(pop)
}

/* Insert char* into NaN. You are respsible for the lifetime of s. */
inline double
ensure_make_nan(const char* const s)
{
ensure_union u;

if (0 == s)
return ensure_ok;

u.l[ensure_lo()] = 0x7FFFFFFF;
#pragma warning(push)
#pragma warning(disable: 4311)
u.l[ensure_hi()] = (long)s;
#pragma warning(pop)

return u.d;
}

#ifdef isnan
#undef isnan
#endif

#endif /* ENSURE_H */

Nov 14 '05 #27

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

Similar topics

2
by: Enigman O'Maly | last post by:
I'm still somewhat new to object style programming (as will become evident), using VBA in Excel 2000 to automate some previously manual functions. I've defined a class module so that I can...
2
by: Alf P. Steinbach | last post by:
The sixth part of my attempted Correct C++ tutorial is now available, although for now only in Word format (use free Open Office if no Word), and also, it's not yet been reviewed at all -- ...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
0
by: Gary O'Malley | last post by:
I really don't know how to get started with code that declares a new object and then makes that object an MSAccess Application. Then with that object call functions\sub routines that exist within...
2
by: Matthew Hood | last post by:
I'm at a loss on how to create global functions for my website. Essentially, I have several different functions I use throughout my site and I want to be able to put these in 1 file and call them...
47
by: rawCoder | last post by:
Hi, Just wanted to know if there is any speed difference between VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc. ..NETs Convert.To<...> methods. And which is better to be...
3
by: UJ | last post by:
I am going to write a class that will inherit from SqlCommand and I want to disable certain routines in the SqlCommand and add a couple of new routines. How would I go about doing that? I...
7
by: Ben Finney | last post by:
Howdy all, Ned Batchelder blogged about a debate over checking function parameters, and to what extent dynamic typing should be relied upon. I was one of many who commented, but I wrote what...
0
by: TechWitch | last post by:
In my current environment, we have a 64-bit instance (DB2/AIX64 8.2.4) where we have at least one function that was left in 32-bit mode (not JAVA). According to the IBM documentation it is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.