OK. LETS START REAL PROGRAMMING IN C FOR PROBLEMS!!!

8

88888 Dihedral

I suggest a type of a name like longreal or what ever that just can behave like 1L in python, maybe 1LL in C, since 1L was used.

Figure out the other two build in types that could enhance C to beat other languages.
 
M

Markus Wichmann

Le 20/11/11 20:12, 88888 Dihedral a écrit :

Euler's constant is the limit of the sum when N goes to infinity of:

1 + 1/2 + 1/3 + 1/4 + ... 1/N - ln(n)

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.
This is related to the PSI function (digamma) by

Euler constant = -psi(1)

This can be calculated in C with this program:
(Using lcc-win. Other compilers will be able to do this too
but in a different way)

So... basically you say this cannot be done in ISO C? Or is it just to
hard? Or do you want to promote yourself? And what the hell is psi()
meant to be? My man page collection doesn't know it and it knows stuff
like bessel functions...

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. 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.
d:\lcc\mc79\test>type teuler.c
#include <qfloat.h>
#include <specialfns.h>
#include <stdio.h>
int main(void)
{
qfloat e=psiq(1.0q);
printf("Euler constant is:\n%.95qf\n",-e);
}

So, not only does this program feature strange types, it also has
unknown suffixes to literals and extensions to printf().

I don't know exactly, but I'd file this code under "Not C"!

HTH,
Markus
 
K

Kleuskes & Moos

I suggest a type of a name like longreal or what ever that just can
behave like 1L in python, maybe 1LL in C, since 1L was used.

You mean, like a ''double'' (short for double precision float) ?

-------------------------------------------------------------------------------
______________________________
< MY income is ALL disposable! >
------------------------------
\
\
___
{~._.~}
( Y )
()~*~()
(_)-(_)
-------------------------------------------------------------------------------
 
J

jacob navia

Le 21/11/11 13:54, Vincenzo Mercuri a écrit :
Euler's *constant* and Euler's *number* are actually different
in meaning. While the former usually refers to "gamma", also
known as Euler-Mascheroni constant, the latter is just "e",
also known as Napier's constant (or number). If the OP was
really asking something worth replying, he most likely meant
to ask for an algorithm to compute the Napier's constant.
But let's say that he meant "gamma". Well, a library which
already provides that number is not really what we would have
answered here. There are many math-libraries around the net.
It's cool that lcc already provides one, but nobody could ever
verify the implemented algorithm since lcc is not open-source.

Using your logic, you can't use Mathlab then, or Mathematica,
or MSVC, or Maple.

None of those programs are open source.

I explained the algorithm and the library that lcc-win uses.
The Cephes mathematical library is available in source form
 
J

jacob navia

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.
Or is it just to
hard?

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.
 
8

88888 Dihedral

OK, I am just tired of GCC or VC. If LCC-WIN for 30EUROS can solve my projects I'll pay for that!
 
B

Ben Bacarisse

Markus Wichmann said:
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.)

What Jacob wrote is not the harmonic series. OK, it has a minor typo
(ln(n) should be ln(N)) but that does not seem to be what you are
commenting on.
Euler's number is actually

1+ 1 + 1/2! + 1/3! + 1/4! + ...

There are two numbers that *might* go by that name, and the limit of the
series Jacob posted is one of them. It is unambiguously named the
"Euler-Mascheroni Constant" and it often gets written as a lower-case
gamma. e is so ubiquitous that it is only very rarely referred by any
other name, and I've never heard it called Euler's anything.

<snip>
 
M

Malcolm McLean

e is so ubiquitous that it is only very rarely referred by any
other name, and I've never heard it called Euler's anything.
A Google turned up 836,000 uses of the phrase "Euler's number". Some
of those might refer to the telephone number of people called Euler,
but most will be e.
 
B

BartC

Malcolm McLean said:
A Google turned up 836,000 uses of the phrase "Euler's number". Some
of those might refer to the telephone number of people called Euler,
but most will be e.

This doesn't make things any clearer. Is this number 2.718..., or 0.577...,
or one of the sequence 1, 0, -1, 0, 5, 0, -61,... as suggested by Wikipedia?
(I've already eliminated the ones that are obviously phone numbers.)
 
M

Malcolm McLean

This doesn't make things any clearer. Is this number 2.718..., or 0.577....,
or one of the sequence 1, 0, -1, 0, 5, 0, -61,... as suggested by Wikipedia?
(I've already eliminated the ones that are obviously phone numbers.)
2.718 - Euler's number
0.577 - Euler's constant
1, 0, -1, 0, 5, 0, -61 - the Euler numbers
0356 125670 - Euler's number
 
K

Kaz Kylheku

A Google turned up 836,000 uses of the phrase "Euler's number". Some
of those might refer to the telephone number of people called Euler,
but most will be e.

It's hard to imagine that someone with the mathematical stature of Euler
would be attributed with only one number. :)
 
J

James Kuyper

This doesn't make things any clearer. Is this number 2.718..., or 0.577...,
or one of the sequence 1, 0, -1, 0, 5, 0, -61,... as suggested by Wikipedia?
(I've already eliminated the ones that are obviously phone numbers.)

You've found numerous occurrences of 'e' as a symbol for 0.577... or one
of those sequences? Citations, please?
 
J

James Kuyper

It's hard to imagine that someone with the mathematical stature of Euler
would be attributed with only one number. :)

Nonetheless, there's only one thing commonly called "Euler's Number",
and a different thing called "the Euler constant", even though both of
them are numbers, and both are constants.
 
L

Lew Pitcher

That is Euler's number.
https://www.google.com/search?q=euler's+number

Hit #1 leads to
http://en.wikipedia.org/wiki/E_(mathematical_constant)
"The mathematical constant e is the unique real number such that the
value of the
derivative (slope of the tangent line) of the function f(x) = ex at
the point x = 0
is equal to 1."

Hit #2 leads to
http://en.wikipedia.org/wiki/Euler_number
"In the area of number theory, the Euler numbers are a sequence En
of integers
(sequence A122045 in OEIS) defined by the following Taylor series
expansion:
\frac{1}{\cosh t} = \frac{2}{e^{t} + e^ {-t} } = \sum_{n=0}
^{\infin}
\frac{E_n}{n!} \cdot t^n\!
where cosh t is the hyperbolic cosine."

I /believed/ that the OP meant #1 ("Euler's Number" aka /e/), but his
vague reference to the integer portion of the value being 1 lead me to
wonder if I was wrong.
 
L

Lew Pitcher

Le 20/11/11 20:12, 88888 Dihedral a écrit :


Euler's constant is the limit of the sum when N goes to infinity of:

1 + 1/2 + 1/3 + 1/4 + ... 1/N - ln(n)

See my blog article http://pitcher.digitalfreehold.ca/code/natlog
"This program computes the value of e to 5,000 decimal places, and
was inspired by
the article "The Impossible Dream: Computing e to 116,000 places
with a Personal
Computer" by Stephen Wozniak, published in Byte Magazine Vol 6,
Issue 6 (June 1981,
pp392)."
 
K

Keith Thompson

Markus Wichmann said:
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.)

You missed the trailing "- ln(n)" term. It's the *difference* between
the sum of the harmonic series and the natual logarithm.

http://en.wikipedia.org/wiki/Euler–Mascheroni_constant

[...]
 
P

Phil Carmody

Kleuskes & Moos said:
Such as?


Me neither. In fact i think it's evolved quite a bit.

It's evolved almost quite far enough, and perhaps too far in some
directions. I think that's one of its beauties, it's still
recognisable as the language I first saw in the 80s.

I was reading about a <ahem> very closely related language recently
and was delighted to see that a feature that was standardized after I
last seriously used the full language, about 10 years ago, is now
deprecated. The "designers", and I use the term very loosely - they're
clearly bodgers who can't think things through thoroughly enough, of
that language should be taken outside and whipped. And their language
derided for the mess that it is.

Oh - do you not think that a 15-line long .sig is a bit excessive
attached to a post with only two lines of original text?

Phil
 
B

Ben Bacarisse

Lew Pitcher said:
See my blog article http://pitcher.digitalfreehold.ca/code/natlog
"This program computes the value of e to 5,000 decimal places, and
was inspired by
the article "The Impossible Dream: Computing e to 116,000 places
with a Personal
Computer" by Stephen Wozniak, published in Byte Magazine Vol 6,
Issue 6 (June 1981,
pp392)."

The location of you reply suggests a connection between the article and
the series directly above it but I can't see a direct connection. The
last thing this thread needs is more confusion between e and gamma!
 
B

Ben Bacarisse

Malcolm McLean said:
2.718 - Euler's number
0.577 - Euler's constant
1, 0, -1, 0, 5, 0, -61 - the Euler numbers
0356 125670 - Euler's number

Or
Napier's constant: 2.718...
Euler-Mascheroni constant: 0.577...
Euler's numbers: 2, 12, 15, 22, 27, 35 bonus ball 19
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top