19ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes/* $NetBSD: catanl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ 29ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 39ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes/*- 49ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * Copyright (c) 2007 The NetBSD Foundation, Inc. 59ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * All rights reserved. 69ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * 79ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * This code is derived from software written by Stephen L. Moshier. 89ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * It is redistributed by the NetBSD Foundation by permission of the author. 99ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * 109ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * Redistribution and use in source and binary forms, with or without 119ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * modification, are permitted provided that the following conditions 129ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * are met: 139ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * 1. Redistributions of source code must retain the above copyright 149ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * notice, this list of conditions and the following disclaimer. 159ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright 169ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * notice, this list of conditions and the following disclaimer in the 179ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * documentation and/or other materials provided with the distribution. 189ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * 199ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 209ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 219ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 229ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 239ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 249ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 259ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 269ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 279ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 289ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 299ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes * POSSIBILITY OF SUCH DAMAGE. 309ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes */ 319ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 329ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#include "../src/namespace.h" 339ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#include <complex.h> 349ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#include <math.h> 359ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#include <float.h> 369ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#include "cephes_subrl.h" 379ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 389ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#ifdef __weak_alias 399ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes__weak_alias(catanl, _catanl) 409ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#endif 419ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 429ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#define MAXNUM LDBL_MAX 439ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 449ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hugheslong double complex 459ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughescatanl(long double complex z) 469ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes{ 479ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes long double complex w; 489ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes long double a, t, x, x2, y; 499ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 509ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes x = creall(z); 519ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes y = cimagl(z); 529ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 539ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes if ((x == 0.0L) && (y > 1.0L)) 549ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes goto ovrf; 559ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 569ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes x2 = x * x; 579ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes a = 1.0L - x2 - (y * y); 589ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes if (a == 0.0) 599ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes goto ovrf; 609ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 619ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes t = 0.5L * atan2l(2.0L * x, a); 629ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes w = _redupil(t); 639ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 649ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes t = y - 1.0L; 659ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes a = x2 + (t * t); 669ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes if (a == 0.0L) 679ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes goto ovrf; 689ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 699ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes t = y + 1.0L; 709ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes a = (x2 + (t * t))/a; 719ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes w = w + (0.25L * logl(a)) * I; 729ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes return w; 739ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 749ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughesovrf: 759ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#if 0 769ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes mtherr ("catanl", OVERFLOW); 779ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes#endif 789ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes w = MAXNUM + MAXNUM * I; 799ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes return w; 809ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes} 81