1/* $OpenBSD: k_cosl.c,v 1.1 2008/12/09 20:00:35 martynas Exp $ */ 2/* From: @(#)k_cos.c 1.3 95/01/18 */ 3/* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. 7 * 8 * Developed at SunSoft, a Sun Microsystems, Inc. business. 9 * Permission to use, copy, modify, and distribute this 10 * software is freely granted, provided that this notice 11 * is preserved. 12 * ==================================================== 13 */ 14 15/* 16 * ld128 version of k_cos.c. See ../k_cos.c for most comments. 17 */ 18 19#include "math_private.h" 20 21/* 22 * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]: 23 * |cos(x) - c(x))| < 2**-122.0 24 * 25 * 113-bit precision requires more care than 64-bit precision, since 26 * simple methods give a minimax polynomial with coefficient for x^2 27 * that is 1 ulp below 0.5, but we want it to be precisely 0.5. See 28 * ../ld80/k_cosl.c for more details. 29 */ 30static const double 31one = 1.0; 32 33static const long double 34C1 = 0.04166666666666666666666666666666658424671L, 35C2 = -0.001388888888888888888888888888863490893732L, 36C3 = 0.00002480158730158730158730158600795304914210L, 37C4 = -0.2755731922398589065255474947078934284324e-6L, 38C5 = 0.2087675698786809897659225313136400793948e-8L, 39C6 = -0.1147074559772972315817149986812031204775e-10L, 40C7 = 0.4779477332386808976875457937252120293400e-13L; 41 42static const double 43C8 = -0.1561920696721507929516718307820958119868e-15, 44C9 = 0.4110317413744594971475941557607804508039e-18, 45C10 = -0.8896592467191938803288521958313920156409e-21, 46C11 = 0.1601061435794535138244346256065192782581e-23; 47 48long double 49__kernel_cosl(long double x, long double y) 50{ 51 long double hz,z,r,w; 52 53 z = x*x; 54 r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+ 55 z*(C8+z*(C9+z*(C10+z*C11)))))))))); 56 hz = 0.5*z; 57 w = one-hz; 58 return w + (((one-w)-hz) + (z*r-x*y)); 59} 60