/* @(#)k_rem_pio2.c 1.3 95/01/18 */
/*
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright ( C ) 1993 by Sun Microsystems , Inc . All rights reserved .
*
* Developed at SunSoft , a Sun Microsystems , Inc . business .
* Permission to use , copy , modify , and distribute this
* software is freely granted , provided that this notice
* is preserved .
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
//#include <sys/cdefs.h>
//__FBSDID("$FreeBSD$");
/*
* _ _ kernel_rem_pio2 ( x , y , e0 , nx , prec )
* double x [ ] , y [ ] ; int e0 , nx , prec ;
*
* _ _ kernel_rem_pio2 return the last three digits of N with
* y = x - N * pi / 2
* so that | y | < pi / 2 .
*
* The method is to compute the integer ( mod 8 ) and fraction parts of
* ( 2 / pi ) * x without doing the full multiplication . In general we
* skip the part of the product that are known to be a huge integer (
* more accurately , = 0 mod 8 ) . Thus the number of operations are
* independent of the exponent of the input .
*
* ( 2 / pi ) is represented by an array of 24 - bit integers in ipio2 [ ] .
*
* Input parameters :
* x [ ] The input value ( must be positive ) is broken into nx
* pieces of 24 - bit integers in double precision format .
* x [ i ] will be the i - th 24 bit of x . The scaled exponent
* of x [ 0 ] is given in input parameter e0 ( i . e . , x [ 0 ] * 2 ^ e0
* match x ' s up to 24 bits .
*
* Example of breaking a double positive z into x [ 0 ] + x [ 1 ] + x [ 2 ] :
* e0 = ilogb ( z ) - 23
* z = scalbn ( z , - e0 )
* for i = 0 , 1 , 2
* x [ i ] = floor ( z )
* z = ( z - x [ i ] ) * 2 * * 24
*
*
* y [ ] output result in an array of double precision numbers .
* The dimension of y [ ] is :
* 24 - bit precision 1
* 53 - bit precision 2
* 64 - bit precision 2
* 113 - bit precision 3
* The actual value is the sum of them . Thus for 113 - bit
* precision , one may have to do something like :
*
* long double t , w , r_head , r_tail ;
* t = ( long double ) y [ 2 ] + ( long double ) y [ 1 ] ;
* w = ( long double ) y [ 0 ] ;
* r_head = t + w ;
* r_tail = w - ( r_head - t ) ;
*
* e0 The exponent of x [ 0 ] . Must be < = 16360 or you need to
* expand the ipio2 table .
*
* nx dimension of x [ ]
*
* prec an integer indicating the precision :
* 0 24 bits ( single )
* 1 53 bits ( double )
* 2 64 bits ( extended )
* 3 113 bits ( quad )
*
* External function :
* double scalbn ( ) , floor ( ) ;
*
*
* Here is the description of some local variables :
*
* jk jk + 1 is the initial number of terms of ipio2 [ ] needed
* in the computation . The minimum and recommended value
* for jk is 3 , 4 , 4 , 6 for single , double , extended , and quad .
* jk + 1 must be 2 larger than you might expect so that our
* recomputation test works . ( Up to 24 bits in the integer
* part ( the 24 bits of it that we compute ) and 23 bits in
* the fraction part may be lost to cancellation before we
* recompute . )
*
* jz local integer variable indicating the number of
* terms of ipio2 [ ] used .
*
* jx nx - 1
*
* jv index for pointing to the suitable ipio2 [ ] for the
* computation . In general , we want
* ( 2 ^ e0 * x [ 0 ] * ipio2 [ jv - 1 ] * 2 ^ ( - 24 jv ) ) / 8
* is an integer . Thus
* e0 - 3 - 24 * jv > = 0 or ( e0 - 3 ) / 24 > = jv
* Hence jv = max ( 0 , ( e0 - 3 ) / 24 ) .
*
* jp jp + 1 is the number of terms in PIo2 [ ] needed , jp = jk .
*
* q [ ] double array with integral value , representing the
* 24 - bits chunk of the product of x and 2 / pi .
*
* q0 the corresponding exponent of q [ 0 ] . Note that the
* exponent for q [ i ] would be q0 - 24 * i .
*
* PIo2 [ ] double precision array , obtained by cutting pi / 2
* into 24 bits chunks .
*
* f [ ] ipio2 [ ] in floating point
*
* iq [ ] integer array by breaking up q [ ] in 24 - bits chunk .
*
* fq [ ] final product of x * ( 2 / pi ) in fq [ 0 ] , . . , fq [ jk ]
*
* ih integer . If > 0 it indicates q [ ] is > = 0 . 5 , hence
* it also indicates the * sign * of the result .
*
*/
/*
* Constants :
* The hexadecimal values are the intended ones for the following
* constants . The decimal values may be used , provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown .
*/
#include <float .h>
#include <math.h>
#include "math_private.h"
static const int init_jk[] = {3 ,4 ,4 ,6 }; /* initial value for jk */
/*
* Table of constants for 2 / pi , 396 Hex digits ( 476 decimal ) of 2 / pi
*
* integer array , contains the ( 24 * i ) - th to ( 24 * i + 23 ) - th
* bit of 2 / pi after binary point . The corresponding
* floating value is
*
* ipio2 [ i ] * 2 ^ ( - 24 ( i + 1 ) ) .
*
* NB : This table must have at least ( e0 - 3 ) / 24 + jk terms .
* For quad precision ( e0 < = 16360 , jk = 6 ) , this is 686 .
*/
static const int32_t ipio2[] = {
0 xA2F983, 0 x6E4E44, 0 x1529FC, 0 x2757D1, 0 xF534DD, 0 xC0DB62,
0 x95993C, 0 x439041, 0 xFE5163, 0 xABDEBB, 0 xC561B7, 0 x246E3A,
0 x424DD2, 0 xE00649, 0 x2EEA09, 0 xD1921C, 0 xFE1DEB, 0 x1CB129,
0 xA73EE8, 0 x8235F5, 0 x2EBB44, 0 x84E99C, 0 x7026B4, 0 x5F7E41,
0 x3991D6, 0 x398353, 0 x39F49C, 0 x845F8B, 0 xBDF928, 0 x3B1FF8,
0 x97FFDE, 0 x05980F, 0 xEF2F11, 0 x8B5A0A, 0 x6D1F6D, 0 x367ECF,
0 x27CB09, 0 xB74F46, 0 x3F669E, 0 x5FEA2D, 0 x7527BA, 0 xC7EBE5,
0 xF17B3D, 0 x0739F7, 0 x8A5292, 0 xEA6BFB, 0 x5FB11F, 0 x8D5D08,
0 x560330, 0 x46FC7B, 0 x6BABF0, 0 xCFBC20, 0 x9AF436, 0 x1DA9E3,
0 x91615E, 0 xE61B08, 0 x659985, 0 x5F14A0, 0 x68408D, 0 xFFD880,
0 x4D7327, 0 x310606, 0 x1556CA, 0 x73A8C9, 0 x60E27B, 0 xC08C6B,
#if LDBL_MAX_EXP > 1024
#if LDBL_MAX_EXP > 16384
#error "ipio2 table needs to be expanded"
#endif
0 x47C419, 0 xC367CD, 0 xDCE809, 0 x2A8359, 0 xC4768B, 0 x961CA6,
0 xDDAF44, 0 xD15719, 0 x053EA5, 0 xFF0705, 0 x3F7E33, 0 xE832C2,
0 xDE4F98, 0 x327DBB, 0 xC33D26, 0 xEF6B1E, 0 x5EF89F, 0 x3A1F35,
0 xCAF27F, 0 x1D87F1, 0 x21907C, 0 x7C246A, 0 xFA6ED5, 0 x772D30,
0 x433B15, 0 xC614B5, 0 x9D19C3, 0 xC2C4AD, 0 x414D2C, 0 x5D000C,
0 x467D86, 0 x2D71E3, 0 x9AC69B, 0 x006233, 0 x7CD2B4, 0 x97A7B4,
0 xD55537, 0 xF63ED7, 0 x1810A3, 0 xFC764D, 0 x2A9D64, 0 xABD770,
0 xF87C63, 0 x57B07A, 0 xE71517, 0 x5649C0, 0 xD9D63B, 0 x3884A7,
0 xCB2324, 0 x778AD6, 0 x23545A, 0 xB91F00, 0 x1B0AF1, 0 xDFCE19,
0 xFF319F, 0 x6A1E66, 0 x615799, 0 x47FBAC, 0 xD87F7E, 0 xB76522,
0 x89E832, 0 x60BFE6, 0 xCDC4EF, 0 x09366C, 0 xD43F5D, 0 xD7DE16,
0 xDE3B58, 0 x929BDE, 0 x2822D2, 0 xE88628, 0 x4D58E2, 0 x32CAC6,
0 x16E308, 0 xCB7DE0, 0 x50C017, 0 xA71DF3, 0 x5BE018, 0 x34132E,
0 x621283, 0 x014883, 0 x5B8EF5, 0 x7FB0AD, 0 xF2E91E, 0 x434A48,
0 xD36710, 0 xD8DDAA, 0 x425FAE, 0 xCE616A, 0 xA4280A, 0 xB499D3,
0 xF2A606, 0 x7F775C, 0 x83C2A3, 0 x883C61, 0 x78738A, 0 x5A8CAF,
0 xBDD76F, 0 x63A62D, 0 xCBBFF4, 0 xEF818D, 0 x67C126, 0 x45CA55,
0 x36D9CA, 0 xD2A828, 0 x8D61C2, 0 x77C912, 0 x142604, 0 x9B4612,
0 xC459C4, 0 x44C5C8, 0 x91B24D, 0 xF31700, 0 xAD43D4, 0 xE54929,
0 x10D5FD, 0 xFCBE00, 0 xCC941E, 0 xEECE70, 0 xF53E13, 0 x80F1EC,
0 xC3E7B3, 0 x28F8C7, 0 x940593, 0 x3E71C1, 0 xB3092E, 0 xF3450B,
0 x9C1288, 0 x7B20AB, 0 x9FB52E, 0 xC29247, 0 x2F327B, 0 x6D550C,
0 x90A772, 0 x1FE76B, 0 x96CB31, 0 x4A1679, 0 xE27941, 0 x89DFF4,
0 x9794E8, 0 x84E6E2, 0 x973199, 0 x6BED88, 0 x365F5F, 0 x0EFDBB,
0 xB49A48, 0 x6CA467, 0 x427271, 0 x325D8D, 0 xB8159F, 0 x09E5BC,
0 x25318D, 0 x3974F7, 0 x1C0530, 0 x010C0D, 0 x68084B, 0 x58EE2C,
0 x90AA47, 0 x02E774, 0 x24D6BD, 0 xA67DF7, 0 x72486E, 0 xEF169F,
0 xA6948E, 0 xF691B4, 0 x5153D1, 0 xF20ACF, 0 x339820, 0 x7E4BF5,
0 x6863B2, 0 x5F3EDD, 0 x035D40, 0 x7F8985, 0 x295255, 0 xC06437,
0 x10D86D, 0 x324832, 0 x754C5B, 0 xD4714E, 0 x6E5445, 0 xC1090B,
0 x69F52A, 0 xD56614, 0 x9D0727, 0 x50045D, 0 xDB3BB4, 0 xC576EA,
0 x17F987, 0 x7D6B49, 0 xBA271D, 0 x296996, 0 xACCCC6, 0 x5414AD,
0 x6AE290, 0 x89D988, 0 x50722C, 0 xBEA404, 0 x940777, 0 x7030F3,
0 x27FC00, 0 xA871EA, 0 x49C266, 0 x3DE064, 0 x83DD97, 0 x973FA3,
0 xFD9443, 0 x8C860D, 0 xDE4131, 0 x9D3992, 0 x8C70DD, 0 xE7B717,
0 x3BDF08, 0 x2B3715, 0 xA0805C, 0 x93805A, 0 x921110, 0 xD8E80F,
0 xAF806C, 0 x4BFFDB, 0 x0F9038, 0 x761859, 0 x15A562, 0 xBBCB61,
0 xB989C7, 0 xBD4010, 0 x04F2D2, 0 x277549, 0 xF6B6EB, 0 xBB22DB,
0 xAA140A, 0 x2F2689, 0 x768364, 0 x333B09, 0 x1A940E, 0 xAA3A51,
0 xC2A31D, 0 xAEEDAF, 0 x12265C, 0 x4DC26D, 0 x9C7A2D, 0 x9756C0,
0 x833F03, 0 xF6F009, 0 x8C402B, 0 x99316D, 0 x07B439, 0 x15200C,
0 x5BC3D8, 0 xC492F5, 0 x4BADC6, 0 xA5CA4E, 0 xCD37A7, 0 x36A9E6,
0 x9492AB, 0 x6842DD, 0 xDE6319, 0 xEF8C76, 0 x528B68, 0 x37DBFC,
0 xABA1AE, 0 x3115DF, 0 xA1AE00, 0 xDAFB0C, 0 x664D64, 0 xB705ED,
0 x306529, 0 xBF5657, 0 x3AFF47, 0 xB9F96A, 0 xF3BE75, 0 xDF9328,
0 x3080AB, 0 xF68C66, 0 x15CB04, 0 x0622FA, 0 x1DE4D9, 0 xA4B33D,
0 x8F1B57, 0 x09CD36, 0 xE9424E, 0 xA4BE13, 0 xB52333, 0 x1AAAF0,
0 xA8654F, 0 xA5C1D2, 0 x0F3F0B, 0 xCD785B, 0 x76F923, 0 x048B7B,
0 x721789, 0 x53A6C6, 0 xE26E6F, 0 x00EBEF, 0 x584A9B, 0 xB7DAC4,
0 xBA66AA, 0 xCFCF76, 0 x1D02D1, 0 x2DF1B1, 0 xC1998C, 0 x77ADC3,
0 xDA4886, 0 xA05DF7, 0 xF480C6, 0 x2FF0AC, 0 x9AECDD, 0 xBC5C3F,
0 x6DDED0, 0 x1FC790, 0 xB6DB2A, 0 x3A25A3, 0 x9AAF00, 0 x9353AD,
0 x0457B6, 0 xB42D29, 0 x7E804B, 0 xA707DA, 0 x0EAA76, 0 xA1597B,
0 x2A1216, 0 x2DB7DC, 0 xFDE5FA, 0 xFEDB89, 0 xFDBE89, 0 x6C76E4,
0 xFCA906, 0 x70803E, 0 x156E85, 0 xFF87FD, 0 x073E28, 0 x336761,
0 x86182A, 0 xEABD4D, 0 xAFE7B3, 0 x6E6D8F, 0 x396795, 0 x5BBF31,
0 x48D784, 0 x16DF30, 0 x432DC7, 0 x356125, 0 xCE70C9, 0 xB8CB30,
0 xFD6CBF, 0 xA200A4, 0 xE46C05, 0 xA0DD5A, 0 x476F21, 0 xD21262,
0 x845CB9, 0 x496170, 0 xE0566B, 0 x015299, 0 x375550, 0 xB7D51E,
0 xC4F133, 0 x5F6E13, 0 xE4305D, 0 xA92E85, 0 xC3B21D, 0 x3632A1,
0 xA4B708, 0 xD4B1EA, 0 x21F716, 0 xE4698F, 0 x77FF27, 0 x80030C,
0 x2D408D, 0 xA0CD4F, 0 x99A520, 0 xD3A2B3, 0 x0A5D2F, 0 x42F9B4,
0 xCBDA11, 0 xD0BE7D, 0 xC1DB9B, 0 xBD17AB, 0 x81A2CA, 0 x5C6A08,
0 x17552E, 0 x550027, 0 xF0147F, 0 x8607E1, 0 x640B14, 0 x8D4196,
0 xDEBE87, 0 x2AFDDA, 0 xB6256B, 0 x34897B, 0 xFEF305, 0 x9EBFB9,
0 x4F6A68, 0 xA82A4A, 0 x5AC44F, 0 xBCF82D, 0 x985AD7, 0 x95C7F4,
0 x8D4D0D, 0 xA63A20, 0 x5F57A4, 0 xB13F14, 0 x953880, 0 x0120CC,
0 x86DD71, 0 xB6DEC9, 0 xF560BF, 0 x11654D, 0 x6B0701, 0 xACB08C,
0 xD0C0B2, 0 x485551, 0 x0EFB1E, 0 xC37295, 0 x3B06A3, 0 x3540C0,
0 x7BDC06, 0 xCC45E0, 0 xFA294E, 0 xC8CAD6, 0 x41F3E8, 0 xDE647C,
0 xD8649B, 0 x31BED9, 0 xC397A4, 0 xD45877, 0 xC5E369, 0 x13DAF0,
0 x3C3ABA, 0 x461846, 0 x5F7555, 0 xF5BDD2, 0 xC6926E, 0 x5D2EAC,
0 xED440E, 0 x423E1C, 0 x87C461, 0 xE9FD29, 0 xF3D6E7, 0 xCA7C22,
0 x35916F, 0 xC5E008, 0 x8DD7FF, 0 xE26A6E, 0 xC6FDB0, 0 xC10893,
0 x745D7C, 0 xB2AD6B, 0 x9D6ECD, 0 x7B723E, 0 x6A11C6, 0 xA9CFF7,
0 xDF7329, 0 xBAC9B5, 0 x5100B7, 0 x0DB2E2, 0 x24BA74, 0 x607DE5,
0 x8AD874, 0 x2C150D, 0 x0C1881, 0 x94667E, 0 x162901, 0 x767A9F,
0 xBEFDFD, 0 xEF4556, 0 x367ED9, 0 x13D9EC, 0 xB9BA8B, 0 xFC97C4,
0 x27A831, 0 xC36EF1, 0 x36C594, 0 x56A8D8, 0 xB5A8B4, 0 x0ECCCF,
0 x2D8912, 0 x34576F, 0 x89562C, 0 xE3CE99, 0 xB920D6, 0 xAA5E6B,
0 x9C2A3E, 0 xCC5F11, 0 x4A0BFD, 0 xFBF4E1, 0 x6D3B8E, 0 x2C86E2,
0 x84D4E9, 0 xA9B4FC, 0 xD1EEEF, 0 xC9352E, 0 x61392F, 0 x442138,
0 xC8D91B, 0 x0AFC81, 0 x6A4AFB, 0 xD81C2F, 0 x84B453, 0 x8C994E,
0 xCC2254, 0 xDC552A, 0 xD6C6C0, 0 x96190B, 0 xB8701A, 0 x649569,
0 x605A26, 0 xEE523F, 0 x0F117F, 0 x11B5F4, 0 xF5CBFC, 0 x2DBC34,
0 xEEBC34, 0 xCC5DE8, 0 x605EDD, 0 x9B8E67, 0 xEF3392, 0 xB817C9,
0 x9B5861, 0 xBC57E1, 0 xC68351, 0 x103ED8, 0 x4871DD, 0 xDD1C2D,
0 xA118AF, 0 x462C21, 0 xD7F359, 0 x987AD9, 0 xC0549E, 0 xFA864F,
0 xFC0656, 0 xAE79E5, 0 x362289, 0 x22AD38, 0 xDC9367, 0 xAAE855,
0 x382682, 0 x9BE7CA, 0 xA40D51, 0 xB13399, 0 x0ED7A9, 0 x480569,
0 xF0B265, 0 xA7887F, 0 x974C88, 0 x36D1F9, 0 xB39221, 0 x4A827B,
0 x21CF98, 0 xDC9F40, 0 x5547DC, 0 x3A74E1, 0 x42EB67, 0 xDF9DFE,
0 x5FD45E, 0 xA4677B, 0 x7AACBA, 0 xA2F655, 0 x23882B, 0 x55BA41,
0 x086E59, 0 x862A21, 0 x834739, 0 xE6E389, 0 xD49EE5, 0 x40FB49,
0 xE956FF, 0 xCA0F1C, 0 x8A59C5, 0 x2BFA94, 0 xC5C1D3, 0 xCFC50F,
0 xAE5ADB, 0 x86C547, 0 x624385, 0 x3B8621, 0 x94792C, 0 x876110,
0 x7B4C2A, 0 x1A2C80, 0 x12BF43, 0 x902688, 0 x893C78, 0 xE4C4A8,
0 x7BDBE5, 0 xC23AC4, 0 xEAF426, 0 x8A67F7, 0 xBF920D, 0 x2BA365,
0 xB1933D, 0 x0B7CBD, 0 xDC51A4, 0 x63DD27, 0 xDDE169, 0 x19949A,
0 x9529A8, 0 x28CE68, 0 xB4ED09, 0 x209F44, 0 xCA984E, 0 x638270,
0 x237C7E, 0 x32B90F, 0 x8EF5A7, 0 xE75614, 0 x08F121, 0 x2A9DB5,
0 x4D7E6F, 0 x5119A5, 0 xABF9B5, 0 xD6DF82, 0 x61DD96, 0 x023616,
0 x9F3AC4, 0 xA1A283, 0 x6DED72, 0 x7A8D39, 0 xA9B882, 0 x5C326B,
0 x5B2746, 0 xED3400, 0 x7700D2, 0 x55F4FC, 0 x4D5901, 0 x8071E0,
#endif
};
static const double PIo2[] = {
1 .57079625129699707031 e+00 , /* 0x3FF921FB, 0x40000000 */
7 .54978941586159635335 e-08 , /* 0x3E74442D, 0x00000000 */
5 .39030252995776476554 e-15 , /* 0x3CF84698, 0x80000000 */
3 .28200341580791294123 e-22 , /* 0x3B78CC51, 0x60000000 */
1 .27065575308067607349 e-29 , /* 0x39F01B83, 0x80000000 */
1 .22933308981111328932 e-36 , /* 0x387A2520, 0x40000000 */
2 .73370053816464559624 e-44 , /* 0x36E38222, 0x80000000 */
2 .16741683877804819444 e-51 , /* 0x3569F31D, 0x00000000 */
};
static const double
zero = 0 .0 ,
one = 1 .0 ,
two24 = 1 .67772160000000000000 e+07 , /* 0x41700000, 0x00000000 */
twon24 = 5 .96046447753906250000 e-08 ; /* 0x3E700000, 0x00000000 */
int
__kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec)
{
int32_t jz,jx,jv,jp,jk,carry,n,iq[20 ],i,j,k,m,q0,ih;
double z,fw,f[20 ],fq[20 ],q[20 ];
/* initialize jk*/
jk = init_jk[prec];
jp = jk;
/* determine jx,jv,q0, note that 3>q0 */
jx = nx-1 ;
jv = (e0-3 )/24 ; if (jv<0 ) jv=0 ;
q0 = e0-24 *(jv+1 );
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
j = jv-jx; m = jx+jk;
for (i=0 ;i<=m;i++,j++) f[i] = (j<0 )? zero : (double ) ipio2[j];
/* compute q[0],q[1],...q[jk] */
for (i=0 ;i<=jk;i++) {
for (j=0 ,fw=0 .0 ;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz = jk;
recompute:
/* distill q[] into iq[] reversingly */
for (i=0 ,j=jz,z=q[jz];j>0 ;i++,j--) {
fw = (double )((int32_t)(twon24* z));
iq[i] = (int32_t)(z-two24*fw);
z = q[j-1 ]+fw;
}
/* compute n */
z = scalbn(z,q0); /* actual value of z */
z -= 8 .0 *floor(z*0 .125 ); /* trim off integer >= 8 */
n = (int32_t) z;
z -= (double )n;
ih = 0 ;
if (q0>0 ) { /* need iq[jz-1] to determine n */
i = (iq[jz-1 ]>>(24 -q0)); n += i;
iq[jz-1 ] -= i<<(24 -q0);
ih = iq[jz-1 ]>>(23 -q0);
}
else if (q0==0 ) ih = iq[jz-1 ]>>23 ;
else if (z>=0 .5 ) ih=2 ;
if (ih>0 ) { /* q > 0.5 */
n += 1 ; carry = 0 ;
for (i=0 ;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if (carry==0 ) {
if (j!=0 ) {
carry = 1 ; iq[i] = 0 x1000000- j;
}
} else iq[i] = 0 xffffff - j;
}
if (q0>0 ) { /* rare case: chance is 1 in 12 */
switch (q0) {
case 1 :
iq[jz-1 ] &= 0 x7fffff; break ;
case 2 :
iq[jz-1 ] &= 0 x3fffff; break ;
}
}
if (ih==2 ) {
z = one - z;
if (carry!=0 ) z -= scalbn(one,q0);
}
}
/* check if recomputation is needed */
if (z==zero) {
j = 0 ;
for (i=jz-1 ;i>=jk;i--) j |= iq[i];
if (j==0 ) { /* need recomputation */
for (k=1 ;iq[jk-k]==0 ;k++); /* k = no. of terms needed */
for (i=jz+1 ;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (double ) ipio2[jv+i];
for (j=0 ,fw=0 .0 ;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
/* chop off zero terms */
if (z==0 .0 ) {
jz -= 1 ; q0 -= 24 ;
while (iq[jz]==0 ) { jz--; q0-=24 ;}
} else { /* break z into 24-bit if necessary */
z = scalbn(z,-q0);
if (z>=two24) {
fw = (double )((int32_t)(twon24*z));
iq[jz] = (int32_t)(z-two24*fw);
jz += 1 ; q0 += 24 ;
iq[jz] = (int32_t) fw;
} else iq[jz] = (int32_t) z ;
}
/* convert integer "bit" chunk to floating-point value */
fw = scalbn(one,q0);
for (i=jz;i>=0 ;i--) {
q[i] = fw*(double )iq[i]; fw*=twon24;
}
/* compute PIo2[0,...,jp]*q[jz,...,0] */
for (i=jz;i>=0 ;i--) {
for (fw=0 .0 ,k=0 ;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
/* compress fq[] into y[] */
switch (prec) {
case 0 :
fw = 0 .0 ;
for (i=jz;i>=0 ;i--) fw += fq[i];
y[0 ] = (ih==0 )? fw: -fw;
break ;
case 1 :
case 2 :
fw = 0 .0 ;
for (i=jz;i>=0 ;i--) fw += fq[i];
STRICT_ASSIGN(double ,fw,fw);
y[0 ] = (ih==0 )? fw: -fw;
fw = fq[0 ]-fw;
for (i=1 ;i<=jz;i++) fw += fq[i];
y[1 ] = (ih==0 )? fw: -fw;
break ;
case 3 : /* painful */
for (i=jz;i>0 ;i--) {
fw = fq[i-1 ]+fq[i];
fq[i] += fq[i-1 ]-fw;
fq[i-1 ] = fw;
}
for (i=jz;i>1 ;i--) {
fw = fq[i-1 ]+fq[i];
fq[i] += fq[i-1 ]-fw;
fq[i-1 ] = fw;
}
for (fw=0 .0 ,i=jz;i>=2 ;i--) fw += fq[i];
if (ih==0 ) {
y[0 ] = fq[0 ]; y[1 ] = fq[1 ]; y[2 ] = fw;
} else {
y[0 ] = -fq[0 ]; y[1 ] = -fq[1 ]; y[2 ] = -fw;
}
}
return n&7 ;
}
Messung V0.5 in Prozent C=92 H=50 G=73
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-08-24)
¤
*© Formatika GbR, Deutschland