19ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes/* $NetBSD: ctanl.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#define MAXNUM LDBL_MAX 399ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 409ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hugheslong double complex 419ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughesctanl(long double complex z) 429ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes{ 439ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes long double complex w; 449ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes long double d; 459ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 469ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes d = cosl(2.0L * creall(z)) + coshl(2.0L * cimagl(z)); 479ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 489ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes if (fabsl(d) < 0.25L) 499ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes d = _ctansl(z); 509ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 519ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes if (d == 0.0L) { 529ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes /* mtherr ("ctan", OVERFLOW); */ 539ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes w = MAXNUM + MAXNUM * I; 549ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes return w; 559ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes } 569ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes 579ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes w = sinl(2.0L * creall(z)) / d + (sinhl(2.0L * cimagl(z)) / d) * I; 589ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes return w; 599ee6adb003eb5a9855ff6c47f9c150b415a11299Elliott Hughes} 60