Le 21/11/11 14:10, Markus Wichmann a écrit :
Nope., but nearly. Perhaps you want to research the "harmonic series"
(or whatever name they gave it in english...). That series is divergent,
the reason being: For any natural number n there is a natural number m
so that Sum(i=0..m, 1/(n+i))> 1. So the harmonic series adds up an
infinite number of ones and thus goes straight to Infinity. (Or rather,
any number you care to name gets exceeded by that series eventually.)
Euler's number is actually
1+ 1 + 1/2! + 1/3! + 1/4! + ...
So... to calculate the Euler number you'd actually need to keep track of
the current addend. Dunno, something like
e = 2;
factorial = 1;
fact_arg = 2;
for(;
{
factorial *= fact_arg++;
addend = 1/factorial;
e += addend;
}
Filling in the blanks and propably finding a decent library to code the
stuff with (or writing the library yourself... it is not hard if all you
want to do is multiplying and adding and you can wait a bit) is left as
an excercise to the reader.
So... basically you say this cannot be done in ISO C?
No, as yo say, you can write your own exteded precision floats in C.
The core of lcc-win's qfloat library is written in assembler however.
It depends of your budget/motivation if it is too hard. In any case it
was hard for me, but I did finish it.
Or do you want to promote yourself?
I am doing exactly that: promoting the solutions I have built in
lcc-win.
And what the hell is psi()
meant to be?
Well, I gave the definition above. You can also look it up in wikipedia
or in Wolfram's site if you are interested.
My man page collection doesn't know it and it knows stuff
like bessel functions...
Yes, in your machine there is no hint at psi. How bad!
HINT: Get better software for it.
Note: The technical report ISO/IEC IS 14882:1998(E) proposes a
series of mathematical functions to be added to the standard library
in an optional statistics package.
Since I am a compiler writer I follow attentively those meetings and
I have implemented most of that proposal's functions. Among them
<quote>
double digamma(double x); // psi or digamma function.
<end quote>
At the beginning the proposal was designed only for C++ but later
it was extended for C also, and much reworked.
Basically, I think we can all agree on the fact that a normal float or
double won't yield enough precision for thirty decimal places.
Yes. I showed 95 decimal places.
On a
machine using IEEE 754 floating point types, a double has fifty two
binary places. That's 52*lg(2)~~ 15.6 decimal places. So we'd actually
have to write a multiprecision integer (for the factorial stuff) and
floating point library.
Yes. That is what lcc-win has done already for you.
So, not only does this program feature strange types, it also has
unknown suffixes to literals and extensions to printf().
Yes.
I don't know exactly, but I'd file this code under "Not C"!
This is only a product of your *ignorance*. If you would care to
read the ISO C standard, you would notice that there is a section
called "Common extensions" where the standard EXPLICITELY mentions:
<begin quote>
J.5 Common extensions
1 The following extensions are widely used in many systems, but are not
portable to all implementations.
[snip]
J.5.6 Other arithmetic types
1 Additional arithmetic types, such as __int128 or double double, and
their appropriate conversions are defined (6.2.5, 6.3.1). Additional
floating types may have more range or precision than long double, may be
used for evaluating expressions of other floating types, and may be used
to define float_t or double_t.
<end quote>
You do not know (or haven't read) what are you talking about.
Your only motivation is to make believe that my work is not standards
conforming, or otherwise impossible to use because of your
ideological "gut feelings"...
Like most people that attack me in this group.