From: Jonathan Leto <jonathan@leto.net>
To: Brian Gough <bjg@network-theory.co.uk>
Cc: gsl-discuss@sources.redhat.com
Subject: Re: sf_gamma questions
Date: Sat, 01 Dec 2001 18:46:00 -0000 [thread overview]
Message-ID: <20011204000727.A11609@leto.net> (raw)
Message-ID: <20011201184600.D70N5nAo1YGcrbddsZslTM-hDz9oVxTlXG8WMR-HowE@z> (raw)
In-Reply-To: <15372.1006.825208.314313@debian>
[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]
Patch is attached to implement my idea. I am not a C programmer
by trade, so let me know if I am tickling Nyarlathotep or
something.
New output of my difference program:
-------------- Actual error vs. Theoretical Error
Difference (1):0 vs 0
Difference (2):0 vs 0
Difference (3):0 vs 0
Difference (4):0 vs 0
Difference (5):0 vs 0
Difference (6):0 vs 0
Difference (7):0 vs 0
Difference (8):0 vs 0
Difference (9):0 vs 0
Difference (10):0 vs 0
Difference (11):0 vs 0
Difference (12):0 vs 0
Difference (13):0 vs 0
Difference (14):0 vs 0
Difference (15):0 vs 0
Difference (16):0 vs 0
Difference (17):0 vs 0
Difference (18):0 vs 0
Difference (19):0 vs 2.84322508014156
Difference (20):0 vs 54.0212765226897
Difference (21):0 vs 1080.42553045379
Difference (22):0 vs 22688.9361395297
Difference (23):0 vs 499156.595069653
Difference (24):0 vs 11480601.686602
Difference (25):0 vs 275534440.478449
Brian Gough (bjg@network-theory.co.uk) was saying:
> Jonathan Leto writes:
> > Why is the error so large for gamma(x>18) ?
>
> It's computed with an approximation so the relative error is the
> appropriate measure. Note that 1/Gamma(19) is the first value which is
> less than DBL_EPSILON.
>
> > Would it be possible to just return factorial(x-1) if gamma is
> > given an integer argument?
>
> Sounds reasonable to me.
--
jonathan@leto.net
"Wir muessen wissen. Wir werden wissen."
-- David Hilbert, 1931
[-- Attachment #2: gsl-1.0_gamma.patch --]
[-- Type: text/plain, Size: 565 bytes --]
--- gamma.c.orig Mon Dec 3 23:21:36 2001
+++ gamma.c Mon Dec 3 23:53:27 2001
@@ -1247,7 +1247,14 @@
int
gsl_sf_gamma_e(const double x, gsl_sf_result * result)
{
- if(x < 0.5) {
+ int y;
+ y = abs((int)x - x );
+
+ /* if x is an integer as far as we can tell, return factorial(x-1)
+ this gives us much better precision when x>19 or so */
+ if(y < GSL_DBL_EPSILON ){
+ gsl_sf_fact_e((int) x - 1,result);
+ } else if(x < 0.5) {
int rint_x = (int)floor(x+0.5);
double f_x = x - rint_x;
double sgn = ( GSL_IS_EVEN(rint_x) ? 1.0 : -1.0 );
next prev parent reply other threads:[~2001-12-04 5:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-19 13:20 Jonathan Leto
2001-11-26 23:50 ` Jonathan Leto
2001-12-19 13:20 ` Brian Gough
2001-11-29 1:08 ` Brian Gough
2001-12-19 13:20 ` Jonathan Leto [this message]
2001-12-01 18:46 ` Jonathan Leto
2001-12-19 13:20 ` Brian Gough
2001-12-03 15:28 ` Brian Gough
2001-12-19 13:20 ` Jonathan Leto
2001-12-19 13:20 ` Dan, Ho-Jin
2001-11-28 12:19 ` Dan, Ho-Jin
2001-12-19 13:20 ` Jonathan Leto
2002-12-31 9:55 Dherminder Kainth
2002-01-03 2:18 ` Dherminder Kainth
2002-12-31 9:55 ` Brian Gough
2002-01-05 11:37 ` Brian Gough
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20011204000727.A11609@leto.net \
--to=jonathan@leto.net \
--cc=bjg@network-theory.co.uk \
--cc=gsl-discuss@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).