Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #1470
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Sun, 15 Apr 2012 00:26:08 -0500 |
| Message-ID | <4F8A5BF2.17C5@mindspring.com> (permalink) |
| Date | Sun, 15 Apr 2012 01:26:10 -0400 |
| From | pete <pfiland@mindspring.com> |
| Reply-To | pfiland@mindspring.com |
| Organization | PF |
| X-Mailer | Mozilla 3.04Gold (WinNT; I) |
| MIME-Version | 1.0 |
| Newsgroups | sci.math.num-analysis, alt.lang.asm, comp.programming |
| Subject | Re: Exp() function reloaded |
| References | <jmdbuh$fql$1@dont-email.me> |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 88 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 4.154.218.101 |
| X-Trace | sv3-qybtIzi5SFenPLDSCvnBs+QlDG8CasO5HvIoSrsSsamHJ0XpIFVb42YOWIir6jV0mgkdns4FKvJT9de!GhR9MbWNOvsE8XKgtUasmw4xNi8H6yvTr61ovLrNM7YdI0lwxxgD4q/Jexe7D/GH0egHQxQoNRuE!IaXVk+FnzCA= |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 2983 |
| X-Received-Bytes | 3124 |
| Xref | csiph.com comp.programming:1470 |
Cross-posted to 3 groups.
Show key headers only | View raw
hopcode wrote:
>
> Hi,
> here my method for the exponentianal function e^x .
> it is a mix of 2 fundamentals:
> - Taylor series running at a 10 steps for decimals -1.0 < x < +1.0
> - a couple of basic rules of the logarithms.
> it is ~40 lines of code (my Taylors's exp() code + main routine)
> it accepts only +numbers for now, and makes no exaustive check
> on the floats. for those and negative values i leave it to the
> reader's creativity ( being e^-x essentially 1 / e^x ).
I've code Taylors's exp(x) for both positive and negative x in C,
using -1.0 < x < +1.0,
but without making use of e^-x being essentially 1 / e^x.
/* BEGIN new.c output */
fs_expl(20.3) is 654904512.153239
fs_expl(20.3) - 654904512.153230 is 8.583069e-006
fs_expl(-20.3) is 1.526940e-009
fs_expl(-20.3) - 1.526940e-009 is 1.591266e-016
/* END new.c output */
/* BEGIN new.c */
#include <stdio.h>
long double fs_expl(long double x)
{
long unsigned n, square;
long double b, e, old;
for (square = 0; x > 1; x /= 2) {
++square;
}
while (-1 > x) {
++square;
x /= 2;
}
e = b = n = 1;
do {
b /= n++;
b *= x;
e += b;
b /= n++;
b *= x;
old = e;
e += b;
} while (e > old);
while (square-- != 0) {
e *= e;
}
return e;
}
int
main(void)
{
puts("/* BEGIN new.c output */\n");
printf("fs_expl(20.3) is %lf\n",
fs_expl(20.3));
printf("fs_expl(20.3) - 654904512.153230 is %le\n\n",
fs_expl(20.3) - 654904512.153230);
printf("fs_expl(-20.3) is %le\n",
fs_expl(-20.3));
printf("fs_expl(-20.3) - 1.526940e-009 is %le\n\n",
fs_expl(-20.3) - 1.526940e-009);
puts("/* END new.c output */");
return 0;
}
/* END new.c */
--
pete
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
Exp() function reloaded hopcode <hopcode@invalid.de> - 2012-04-15 04:31 +0200
Re: Exp() function reloaded pete <pfiland@mindspring.com> - 2012-04-15 01:26 -0400
Re: Exp() function reloaded hopcode <hopcode@invalid.de> - 2012-04-15 12:18 +0200
Re: Exp() function reloaded pete <pfiland@mindspring.com> - 2012-04-15 09:30 -0400
Re: Exp() function reloaded "io_x" <a@b.c.invalid> - 2012-04-16 09:01 +0200
Re: Exp() function reloaded "io_x" <a@b.c.invalid> - 2012-04-16 11:50 +0200
Re: Exp() function reloaded "io_x" <a@b.c.invalid> - 2012-04-16 15:46 +0200
Re: Exp() function reloaded "io_x" <a@b.c.invalid> - 2012-04-16 16:07 +0200
Re: Exp() function reloaded "io_x" <a@b.c.invalid> - 2012-04-17 09:36 +0200
Re: Exp() function reloaded phreda <pabloreda@gmail.com> - 2012-04-19 19:43 -0700
Re: Exp() function reloaded hopcode <hopcode@invalid.de> - 2012-04-24 14:48 +0200
Re: Exp() function reloaded phreda <pabloreda@gmail.com> - 2012-04-25 12:36 -0700
Re: Exp() function reloaded pete <pfiland@mindspring.com> - 2012-04-16 18:12 -0400
csiph-web