From 2704ff880f3542b7dcf628d56be5d08c17e1b3dd Mon Sep 17 00:00:00 2001 From: obarthel Date: Sat, 12 Jul 2025 12:25:42 +0200 Subject: [PATCH] Implemented the fixes for the tgamma() and tgammaf() functions Thanks go to sodero for providing the fixes. --- library/math_tgamma.c | 12 ++++-------- library/math_tgammaf.c | 8 ++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/library/math_tgamma.c b/library/math_tgamma.c index a8c086c..ae46944 100644 --- a/library/math_tgamma.c +++ b/library/math_tgamma.c @@ -1,10 +1,8 @@ /* - * $Id: math_tgamma.c,v 1.3 2006-01-08 12:04:24 obarthel Exp $ - * * :ts=4 * * Portable ISO 'C' (1994) runtime library for the Amiga computer - * Copyright (c) 2002-2015 by Olaf Barthel + * Copyright (c) 2002-2025 by Olaf Barthel * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,13 +52,11 @@ double tgamma(double x) { int gamma_sign; - double y; + double y; - y = __lgamma(x,&gamma_sign); - if (gamma_sign < 0) - y = -y; + y = __lgamma(x, &gamma_sign); - return y; + return gamma_sign * exp(y); } /****************************************************************************/ diff --git a/library/math_tgammaf.c b/library/math_tgammaf.c index 4da5c8e..a1da902 100644 --- a/library/math_tgammaf.c +++ b/library/math_tgammaf.c @@ -1,6 +1,4 @@ /* - * $Id: math_tgammaf.c,v 1.3 2006-01-08 12:04:24 obarthel Exp $ - * * :ts=4 * * Portable ISO 'C' (1994) runtime library for the Amiga computer @@ -56,11 +54,9 @@ tgammaf(float x) int gamma_sign; float y; - y = __lgammaf(x,&gamma_sign); - if (gamma_sign < 0) - y = -y; + y = __lgammaf(x, &gamma_sign); - return y; + return gamma_sign * expf(y); } /****************************************************************************/