xref: /openbsd/regress/lib/libm/cephes/monotll.c (revision 2ed28c9a)
1 /*	$OpenBSD: monotll.c,v 1.2 2011/07/08 16:49:05 martynas Exp $	*/
2 
3 /*
4  * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* monotll.c
20    Floating point function test vectors.
21    128-bit long double version.
22 
23    Arguments and function values are synthesized for NPTS points in
24    the vicinity of each given tabulated test point.  The points are
25    chosen to be near and on either side of the likely function algorithm
26    domain boundaries.  Since the function programs change their methods
27    at these points, major coding errors or monotonicity failures might be
28    detected.
29 
30    August, 1998
31    S. L. Moshier  */
32 
33 #include <float.h>
34 
35 #if	LDBL_MANT_DIG == 113
36 /* Unit of error tolerance in test[i].thresh.  */
37 static long double MACHEPL = 1.9259299443872358530559779425849273185381E-34L;
38 /* How many times the above error to allow before printing a complaint.
39    If TOL < 0, consider absolute error instead of relative error. */
40 #define TOL 4
41 /* Number of test points to generate on each side of tabulated point.  */
42 #define NPTS 100
43 
44 
45 
46 #include <stdio.h>
47 #include <string.h>
48 
49 /* Avoid including math.h.  */
50 long double frexpl (long double, int *);
51 long double ldexpl (long double, int);
52 
53 /* Functions of one variable.  */
54 long double expl (long double);
55 long double expm1l (long double);
56 long double logl (long double);
57 long double log1pl (long double);
58 long double sinl (long double);
59 long double cosl (long double);
60 long double tanl (long double);
61 long double atanl (long double);
62 long double asinl (long double);
63 long double acosl (long double);
64 long double sinhl (long double);
65 long double coshl (long double);
66 long double tanhl (long double);
67 long double asinhl (long double);
68 long double acoshl (long double);
69 long double atanhl (long double);
70 long double lgammal (long double);
71 long double tgammal (long double);
72 long double fabsl (long double);
73 long double floorl (long double);
74 long double j0l (long double);
75 long double y0l (long double);
76 long double j1l (long double);
77 long double y1l (long double);
78 long double jnl (int, long double);
79 long double ynl (int, long double);
80 
81 /* Data structure of the test.  */
82 struct oneargument
83   {
84     char *name;			/* Name of the function. */
85     long double (*func) (long double); /* Function call.  */
86     long double arg1;		/* Function argument, assumed exact.  */
87     long double answer1;	/* Exact number, close to function value.  */
88     long double answer2;	/* answer1 + answer2 has extended precision. */
89     long double derivative;	/* dy/dx evaluated at x = arg1. */
90     /* Error report threshold. 2 => 1 ulp approximately
91        if thresh < 0 then consider absolute error instead of relative error. */
92     int thresh;
93 
94   };
95 
96 
97 
98 static struct oneargument test1[] =
99 {
100   {"exp", expl, 1.0L, 2.7182769775390625L,
101    4.85091998273536028747135266249775725E-6L,
102    2.71828182845904523536028747135266250E0L, TOL},
103   {"exp", expl, -1.0L, 3.678741455078125e-1L,
104    5.29566362982159552377016146086744581E-6L,
105    3.67879441171442321595523770161460867E-1L, TOL},
106   {"exp", expl, 0.5L, 1.648712158203125L,
107    9.11249700314684865078781416357165378E-6L,
108    1.64872127070012814684865078781416357L, TOL},
109   {"exp", expl, -0.5L, 6.065216064453125e-1L,
110    9.05326732092360379953499118045344192E-6L,
111    6.06530659712633423603799534991180453E-1L, TOL},
112   {"exp", expl, 2.0L, 7.3890533447265625L,
113    2.75420408772723042746057500781318032E-6L,
114    7.38905609893065022723042746057500781E0L, TOL},
115   {"exp", expl, -2.0L, 1.353302001953125e-1L,
116    5.08304130019189399949497248440340763E-6L,
117    1.35335283236612691893999494972484403E-1L, TOL},
118   {"expm1", expm1l, 1.0L, 1.7182769775390625L,
119    4.85091998273536028747135266249775725E-6L,
120    2.71828182845904523536028747135266250E0L, TOL},
121   {"expm1", expm1l, 0.5L, 0.648712158203125L,
122    9.11249700314684865078781416357165378E-6L,
123    1.64872127070012814684865078781416357L, TOL},
124   {"expm1", expm1l, 2.0L, 6.3890533447265625L,
125    2.75420408772723042746057500781318032E-6L,
126    7.38905609893065022723042746057500781E0L, TOL},
127   {"log", logl, 1.41421356237309504880168872420969798L,
128    3.465728759765625E-1L,
129    7.14303410154708616060729088217412434E-7L,
130    7.07106781186547524400844362104849086E-1L, TOL},
131   {"log", logl, 7.07106781186547524400844362104848992E-1L,
132    -3.46588134765625E-1L,
133    1.45444856523452913839392709116493369E-5L,
134    1.41421356237309504880168872420969817E0L, TOL},
135   {"log1p", log1pl, 0.41421356237309504880168872420969798L,
136    3.465728759765625E-1L,
137    7.14303410154708616060729088217412434E-7L,
138    7.07106781186547524400844362104849086E-1L, TOL},
139   {"sin", sinl, 7.85398163397448309615660845819875699E-1L,
140    7.0709228515625E-1L,
141    1.44960302975244008443621048490239551E-5L,
142    7.07106781186547524400844362104849055E-1, TOL},
143   {"sin", sinl, -7.85398163397448309615660845819875699E-1L,
144    -7.071075439453125E-1L,
145    7.62758764975599155637895150976044903E-7L,
146    7.07106781186547524400844362104849055E-1L, TOL},
147   {"sin", sinl, 1.57079632679489661923132169163975140E0L,
148    9.999847412109375E-1L,
149    1.52587890625E-5L,
150    0.0L, TOL},
151   {"sin", sinl, -1.57079632679489661923132169163975140E0L,
152    -1.0L,
153    0.0L,
154    0.0L, TOL},
155   {"sin", sinl, 4.71238898038468985769396507491925433E0L,
156    -1.0L,
157    0.0L,
158    0.0L, TOL},
159   {"sin", sinl, -4.71238898038468985769396507491925420E0L,
160    1.0L,
161    0.0L,
162    0.0L, TOL},
163   {"cos", cosl, 3.92699081698724154807830422909937850E-1L,
164    9.238739013671875E-1L,
165    5.63114409925612818318939678829097061E-6L,
166    -3.82683432365089771728459984030398857E-1L, TOL},
167   {"cos", cosl, 7.85398163397448309615660845819875699E-1L,
168    7.0709228515625E-1L,
169    1.44960302975244008443621048490546146E-5L,
170    -7.07106781186547524400844362104849024E-1L, TOL},
171   {"cos", cosl, 1.17809724509617246442349126872981355E0L,
172    3.826751708984375E-1L,
173    8.26146665227172845998403039889680525E-6L,
174    -9.23879532511286756128183189396788274E-1L, TOL},
175   {"cos", cosl, 1.96349540849362077403915211454968925E0L,
176    -3.826904296875E-1L,
177    6.99732241022827154001596960118331183E-6L,
178    -9.23879532511286756128183189396788308E-1L, TOL},
179   {"cos", cosl, 2.35619449019234492884698253745962710E0L,
180    -7.071075439453125E-1L,
181    7.62758764975599155637895151006704382E-7L,
182    -7.07106781186547524400844362104849085E-1L, TOL},
183   {"cos", cosl, 2.74889357189106908365481296036956495E0L,
184    -9.2388916015625E-1L,
185    9.62764496324387181681060321174221497E-6L,
186    -3.82683432365089771728459984030398937E-1L, TOL},
187   {"cos", cosl, 3.14159265358979323846264338327950280E0L,
188    -1.0L,
189    0.0L,
190    0.0L, TOL},
191   {"tan", tanl, 7.8539816339744830961566084581987569936977E-1L,
192    9.999847412109375E-1L,
193    1.5258789062499999999999999999956640949349E-5L,
194    2.0L, TOL},
195   {"tan", tanl, 1.1780972450961724644234912687298135490547E0L,
196    2.4141998291015625L,
197    1.3733271532548801688724209697856514083701E-5L,
198    6.8284271247461900976033774484193950849601E0L, TOL},
199   {"tan", tanl, 1.96349540849362077403915211454968925E0L,
200    -2.414215087890625L,
201    1.52551752995119831127579030155133768E-6L,
202    6.82842712474619009760337744841939794E0L, TOL},
203   {"tan", tanl, 2.35619449019234492884698253745962710E0L,
204    -1.0000152587890625L,
205    1.52587890624999999999999999998699228E-5L,
206    2.0L, TOL},
207   {"tan", tanl, 2.74889357189106908365481296036956495E0L,
208    -4.14215087890625E-1L,
209    1.52551752995119831127579030183253332E-6L,
210    1.17157287525380990239662255158060392E0L, TOL},
211   {"atan", atanl, 4.14213562373095048801688724209698081E-1L,
212    3.926849365234375E-1L,
213    1.41451752866548078304229099378622950E-5L,
214    8.53553390593273762200422181052424518E-1L, TOL},
215   {"atan", atanl, 1.0L,
216    7.853851318359375E-1L,
217    1.30315615108096156608458198757210493E-5L,
218    0.5L, TOL},
219   {"atan", atanl, 2.41421356237309504880168872420969818E0L,
220    1.1780853271484375L,
221    1.19179477349644234912687298135959800E-5L,
222    1.46446609406726237799577818947575470E-1L, TOL},
223   {"atan", atanl, -2.41421356237309504880168872420969818E0L,
224    -1.1781005859375L,
225    3.34084132753557650873127018640402003E-6L,
226    1.46446609406726237799577818947575470E-1L, TOL},
227   {"atan", atanl, -1.0L,
228    -7.85400390625E-1L,
229    2.22722755169038433915418012427895071E-6L,
230    0.5L, TOL},
231   {"atan", atanl, -4.14213562373095048801688724209698081E-1L,
232    -3.927001953125E-1L,
233    1.11361377584519216957709006213770502E-6L,
234    8.53553390593273762200422181052424518E-1L, TOL},
235   {"asin", asinl, 3.82683432365089771728459984030398880E-1L,
236    3.926849365234375E-1L,
237    1.41451752866548078304229099378750938E-5L,
238    1.08239220029239396879944641073277885E0L, TOL},
239   {"asin", asinl, 0.5L,
240    5.23590087890625E-1L,
241    8.68770767387307710723054658381403286E-6L,
242    1.15470053837925152901829756100391491E0L, TOL},
243   {"asin", asinl, 7.07106781186547524400844362104848992E-1L,
244    7.853851318359375E-1L,
245    1.30315615108096156608458198756544240E-5L,
246    1.41421356237309504880168872420969798E0L, TOL},
247   {"asin", asinl, 9.23879532511286756128183189396788310E-1L,
248    1.1780853271484375L,
249    1.19179477349644234912687298136415266E-5L,
250    2.61312592975275305571328634685437469E0L, TOL},
251   {"asin", asinl, -0.5L,
252    -5.236053466796875E-1L,
253    6.57108138862692289276945341618596714E-6L,
254    1.15470053837925152901829756100391491E0L, TOL},
255   {"asin", asinl, 1.16415321826934814453125E-10L,
256    1.16415321826934814453125E-10L,
257    2.62953635073670601805513180586984061E-31L,
258    1.00000000000000000000677626357803440E0L, TOL},
259   {"asin", asinl, 0.625L,
260    6.751251220703125E-1L,
261    6.41086671914720905626529438801420419E-6L,
262    1.28102523044069706786602935814149630E0L, TOL},
263   {"asin", asinl, 9.74999999999999999999999999999999981E-1L,
264    1.346710205078125L,
265    1.08364149523595315129076204973231659E-5L,
266    4.50035160370409562029946413944745541E0L, TOL},
267   {"acos", acosl, 1.95090322016128267848284868477022248E-1L,
268    1.3744354248046875L,
269    1.13611408470418274064801847825042255E-5L,
270    -1.01959115820831833788387960797568783E0L, TOL},
271   {"acos", acosl, 3.82683432365089771728459984030398880E-1L,
272    1.1780853271484375L,
273    1.19179477349644234912687298135670048E-5L,
274    -1.08239220029239396879944641073277885E0L, TOL},
275   {"acos", acosl, 0.5L,
276    1.0471954345703125L,
277    2.11662628524615421446109316762806572E-6L,
278    -1.15470053837925152901829756100391491E0L, TOL},
279   {"acos", acosl, 7.07106781186547524400844362104848992E-1L,
280    7.853851318359375E-1L,
281    1.30315615108096156608458198757876746E-5L,
282    -1.41421356237309504880168872420969798E0L, TOL},
283   {"acos", acosl, 9.23879532511286756128183189396788310E-1L,
284    3.926849365234375E-1L,
285    1.41451752866548078304229099378005720E-5L,
286    -2.61312592975275305571328634685437469E0L, TOL},
287   {"acos", acosl, 9.80785280403230449126182236134239047E-1L,
288    1.963348388671875E-1L,
289    1.47019821745774039152114549688769794E-5L,
290    -5.12583089548301235759217259235540119E0L, TOL},
291   {"acos", acosl, -0.5L,
292    2.094390869140625L,
293    4.23325257049230842892218633525613145E-6L,
294    -1.15470053837925152901829756100391491E0L, TOL},
295   {"sinh", sinhl, 1.0L,
296    1.1751861572265625L,
297    1.50364172389568823818505956008151557E-5L,
298    1.54308063481524377847790562075706168E0L, TOL},
299   {"sinh", sinhl, 11355.5L,
300    2.13776152623792146713900550884909252E4931L,
301    9.07106102767577900425552629248457689E4896L,
302    2.13776152623792146713900550884909261E4931L, TOL},
303   {"sinh", sinhl, 2.22044604925031308084726333618164062E-16L,
304    2.22044604925031308084726333618164062E-16L,
305    1.82460737542293889443193956157541613E-48L,
306    1.00000000000000000000000000000002465E0L, TOL},
307   {"sinh", sinhl, 40.0L,
308    1.17692633418509992E17L, 7.039499553745174001302586809814832360E-1L,
309    1.176926334185099927039499553745174044E17L, TOL},
310   {"sinh", sinhl, 6.938893903907228377647697925567626953E-18L, /* 2^-57 */
311    6.938893903907228377647697925567626953E-18L,
312    5.568259812692074262792784306565587261E-53L, 1.0L, TOL},
313   {"sinh", sinhl, 11356.375L,
314    5.1282233096855457613267954696602303826729E4931L,
315    6.8582733554584347269625352341976754246942E4896L,
316    5.1282233096855457613267954696602304512556E4931L, TOL},
317   {"cosh", coshl, 40.0L,
318    1.176926334185099927039499553745174054E17L,
319    -1.036733679609227143506056540471143597E-18L,
320    1.176926334185099927039499553745174001E17L, TOL},
321   {"cosh", coshl, 6.938893903907228377647697925567626953E-18L,
322    1.0L, 2.407412430484044816319972428231159158E-35L,
323    6.938893903907228377647697925567627009E-18L, TOL},
324   {"cosh", coshl, 11356.375L,
325     5.128223309685545761326795469660230383E4931L,
326     6.858273355458434726962535234197675425E4896L,
327     5.128223309685545761326795469660230451E4931L, TOL},
328   {"cosh", coshl, 11355.5L,
329    2.13776152623792146713900550884909252E4931L,
330    9.07106102767577900425552629248457689E4896L,
331    2.13776152623792146713900550884909261E4931L, TOL},
332   {"cosh", coshl, 1.0L,
333    1.5430755615234375L,
334    5.07329180627847790562075706168260153E-6L,
335    1.17520119364380145688238185059560082E0L, TOL},
336   {"cosh", coshl, 0.5L,
337    1.12762451171875L,
338    1.45348763078522622516140267201254785E-6L,
339    5.21095305493747361622425626411491559E-1L, TOL},
340   {"tanh", tanhl, 0.5L,
341    4.621124267578125E-1L,
342    4.73050219725850231848364367254873029E-6L,
343    7.86447732965927410149698934343636102E-1L, TOL},
344   {"tanh", tanhl, 5.49306144334054845697622618461262805E-1L,
345    4.999847412109375E-1L,
346    1.52587890624999999999999999999648170E-5L,
347    7.50000000000000000000000000000000035E-1L, TOL},
348   {"tanh", tanhl, 0.625L,
349    5.54595947265625E-1L,
350    3.77508375729399903909532308359605810E-6L,
351    6.92419147969988069630753311573341685E-1L, TOL},
352   {"tanh", tanhl, 40.0L,
353    1.0L,
354    -3.609702775690830344624256714700054777E-35L,
355    7.219405551381660689248513429400109424E-35L, TOL},
356   {"tanh", tanhl, 6.9388939039072283776476979255676269531250E-18L, /* 2^-57 */
357    6.9388939039072283776476979255676269531250E-18L,
358    -1.1136519625384148525585568613131174280582E-52L,
359    9.9999999999999999999999999999999995185175E-1L, TOL},
360   {"tanh", tanhl, 2.775557561562891351059079170227050781E-17L, /* 2^-55 */
361    2.775557561562891351059079170227050781E-17L,
362    -7.127372560245855056374763912403949481E-51L,
363    9.999999999999999999999999999999992296E-1L, TOL},
364   {"tanh", tanhl, 1.0L,
365    7.615814208984375e-1L,
366    1.273505732738811945828260479359041277E-5L,
367    4.199743416140260693944967390417014449E-1L, TOL},
368   {"asinh", asinhl, 0.5L,
369    4.81201171875E-1L,
370    1.06531846034474977589134243684231352E-5L,
371    8.94427190999915878563669467492510494E-1L, TOL},
372   {"asinh", asinhl, 1.0L,
373    8.813629150390625E-1L,
374    1.06719804805252326093249797923090282E-5L,
375    7.07106781186547524400844362104849039E-1L, TOL},
376   {"asinh", asinhl, 2.0L,
377    1.443634033203125L,
378    1.44197568534249327674027310526940555E-6L,
379    4.47213595499957939281834733746255247E-1L, TOL},
380   {"asinh", asinhl, 1.3877787807814456755295395851135253906250E-17L, /*2^-56*/
381    1.3877787807814456755295395851135253906250E-17L,
382    -4.4546078501536594102342274452524694119585E-52L,
383    9.9999999999999999999999999999999990370350E-1L, TOL},
384   {"asinh", asinhl, 1.8014398509481984E16L,
385    38.1230926513671875L,
386    2.2794298045179477666801997120145244851447E-6L,
387    5.5511151231257827021181583404540930096529E-17L, TOL},
388   {"acosh", acoshl, 2.0L,
389    1.31695556640625L,
390    2.33051856670862504634730796844402698E-6L,
391    5.77350269189625764509148780501957456E-1L, TOL},
392   {"acosh", acoshl, 1.5L,
393    9.624176025390625E-1L,
394    6.04758014439499551782684873684627037E-6L,
395    8.94427190999915878563669467492510494E-1L, TOL},
396   {"acosh", acoshl, 1.03125L,
397    2.493438720703125E-1L,
398    9.62177257298785143907541001884302707E-6L,
399    3.96911150685467059808817882107262579E0L, TOL},
400   {"acosh", acoshl, 2.68435456e8L,  /* 2 ^ 28 */
401    20.10125732421875L,
402    1.091201966396963028457033350626731006E-5L,
403    3.725290298461914088349394142282115109E-9L, TOL},
404   {"acosh", acoshl, 1.8014398509481984e16L, /* 2 ^ 54 */
405    38.1230926513671875L,
406    2.279429804517947766680199710473780530E-6L,
407    5.551115123125782702118158340454110115E-17L, TOL},
408   {"acosh", acoshl, 1.073741824e9L, /* 2^30 */
409    21.487548828125L,
410    1.376923330459171735533070637272346848E-5L,
411    9.313225746154785160288967834731580446E-10L, TOL},
412   {"atanh", atanhl, 0.5L,
413    5.493011474609375E-1L,
414    4.99687311734569762261846126285232375E-6L,
415    1.33333333333333333333333333333333333E0L, TOL},
416   {"atanh", atanhl, 6.938893903907228377647697925567626953125E-18,
417    6.938893903907228377647697925567626953125E-18, /* 2^-57 */
418    1.1136519625384148525585568613131174816786E-52, 1.0, TOL},
419 #if 0
420   {"j0", j0l, 16.0L, -1.749114990234375e-1L,
421     1.24250398083151715974822741805925455E-5L,
422    -9.03971756613041862386833024580760244E-2L, -2},
423   {"j0", j0l, 8.0L, 1.716461181640625E-1L,
424     4.68897349140609086940785197200106842E-6L,
425    -2.34636346853914624381276651590454612E-1L, -2},
426   {"j0", j0l, 5.33333333333333333333333333333333333E0L,
427    -6.427001953125e-2L,
428    2.71515994768793872858212682917411767E-6L,
429    3.46125605116223455248039758589625114E-1L, -2},
430   {"j0", j0l, 4.0L, -3.9715576171875e-1L,
431    5.95185490262771340923154830195802438E-6L,
432    6.60433280235491361431854208032750287E-2L, -2},
433   {"j0", j0l, 3.2L, -3.201904296875e-1L,
434    2.26003037709271056745460231434000663E-6L,
435    -2.61343248780504837362986742359905319E-1L, -2},
436   {"j0", j0l, 2.66666666666666666666666666666666667E0L,
437    -1.275634765625e-1L,
438    2.48895584953746034929481550434723427E-6L,
439    -4.51651148392987785778929732830311060E-1L, -2},
440   {"j0", j0l, 2.28571428571428571428571428571428571E0L,
441    6.3262939453125e-2L,
442    7.41898014310740285267270594759284975E-6L,
443    -5.42395540605083481518545728422177515E-1L, -2},
444   {"j0", j0l, 2.0L,
445    2.23876953125e-1L,
446    1.38260162356680518274546499486258252E-5L,
447    -5.76724807756873387202448242269137087E-1L, -2},
448   {"y0", y0l, 16.0L,
449    9.58099365234375e-2L,
450    1.06055727490314207096590322941832776E-6L,
451    -1.77975168939416859630601904359871915E-1L, -2},
452   {"y0", y0l, 8.0L,
453    2.235107421875e-1L,
454    1.07472000662205273234004986203592748E-5L,
455    1.58060461731247494255555266187483550E-1L, -2},
456   {"y0", y0l, 5.33333333333333333333333333333333333E0L,
457    -3.387451171875e-1L,
458    1.48763307492243286439161163883136261E-5L,
459    -3.30338692743198039852173817311267913E-2L, -2},
460   {"y0", y0l, 4.0L,
461    -1.69525146484375E-2L,
462     1.17753233725080963648655528467817595E-5L,
463    -3.97925710557100005253979972450791852E-1L, -2},
464   {"y0", y0l, 3.2L,
465     3.070526123046875E-1L,
466     6.37827715583546999256417236405953385E-7L,
467    -3.70711338441274693924314235987044508E-1L, -2},
468   {"y0", y0l, 2.66666666666666666666666666666666667E0L,
469    4.67864990234375E-1L,
470    1.52461165366402773840048623192120982E-5L,
471    -2.14907152209457967672108494960545800E-1L, -2},
472   {"y0", y0l, 2.28571428571428571428571428571428571E0L,
473    5.18768310546875E-1L,
474    3.23404086137065314580351322765266943E-6L,
475    -4.51747395962233519705260050662299281E-2L, -2},
476   {"y0", y0l, 2.0L,
477    5.103607177734375E-1L,
478    1.49548763076195966065927271578732681E-5L,
479    1.07032431540937546888370772277476637E-1L, -2},
480   {"j1", j1l, 16.0L,
481    9.039306640625e-2L,
482    4.1092550541862386833024580760244495945291E-6L,
483    -1.8054889746246069646832022412944915898260E-1L, -2},
484   {"j1", j1l, 8.0L,
485     2.346343994140625e-1L,
486     1.9474398521243812766515904546115487521615E-6L,
487    1.4232126378081457804320982640316517462483E-1L, -2},
488   {"j1", j1l, 5.3333333333333333333333333333333330765427E0L,
489    -3.4613037109375e-1L,
490    4.7659775265447519602414103748858036315250E-6L,
491    6.3124658798958579773603686238379727242328E-4L, -2},
492   {"j1", j1l, 4.0L,
493    -6.60552978515625e-2L,
494    1.1969828013363856814579196724971272576580E-5L,
495    -3.8063897785796008825079441325087928479376E-1L, -2},
496   {"j1", j1l, 3.2000000000000000000000000000000001540744E0L,
497    2.613372802734375e-1L,
498    5.9685070673373629867423599052573498655055E-6L,
499    -4.0185793490103066896536590238515608924925E-1L, -2},
500   {"j1", j1l, 2.6666666666666666666666666666666665382713E0L,
501    4.516448974609375e-1L,
502    6.2509320502857789297328303110978154167062E-6L,
503    -2.9693016825402088220674935499586226461144E-1L, -2},
504   {"j1", j1l, 2.2857142857142857142857142857142856042326E0L,
505    5.42388916015625e-1L,
506    6.6245894584815185457284221775341820978577E-6L,
507    -1.7402769058145591576151108347875503008807E-1L, -2},
508   {"j1", j1l, 2.0L,
509    5.7672119140625e-1L,
510    3.6163506233872024482422691370869203026897E-6L,
511    -6.4471624737201025549396666484619917634997E-2L, -2},
512   {"y1", y1l, 16.0L,
513    1.779632568359375e-1L,
514    1.1912103479359630601904359871915459722520E-5L,
515    8.4687549021998849415158346880737423611524E-2L, -2},
516   {"y1", y1l, 8.0L,
517    -1.580657958984375e-1L,
518     5.3341671900057444447338125164496726559505E-6L,
519     2.4327904710397215730926780877205580306573E-1L, -2},
520   {"y1", y1l, 5.3333333333333333333333333333333330765427E0L,
521    3.302001953125e-2L,
522    1.3849743069803985217381731126879849266308E-5L,
523    -3.4492409134568573891858434295819796816112E-1L, -2},
524   {"y1", y1l, 4.0L,
525    3.97918701171875e-1L,
526    7.0093852250052539799724507918522711891816E-6L,
527    -1.1642216696433999321713012755985118130829E-1L, -2},
528   {"y1", y1l, 3.2000000000000000000000000000000001540744E0L,
529    3.70697021484375e-1L,
530    1.4316956899693924314235987044537888863453E-5L,
531    1.9120595686950474169565105767128493632383E-1L, -2},
532   {"y1", y1l, 2.6666666666666666666666666666666665382713E0L,
533    2.1490478515625e-1L,
534    2.3670532079676721084949605457501811641711E-6L,
535    3.8729005427236490240034331925211457949310E-1L, -2},
536   {"y1", y1l, 2.2857142857142857142857142857142856042326E0L,
537    4.5166015625e-2L,
538    8.7239712233519705260050662298731987015100E-6L,
539    4.9900759601438865416604067629675208716502E-1L, -2},
540   {"y1", y1l, 2.0L,
541    -1.070404052734375e-1L,
542    7.9737324999531116292277225233633125191018E-6L,
543    5.6389188842021389304079197886589619161188E-1L, -2},
544   {"jnl", NULL, 6.9388939039072283776476979255676269531250E-18L,
545    6.9602982143332406209530299018670212642178E-54L,
546    2.6551531852207537950481339962774251294400E-59L,
547    3.0092655e-36L, -2},
548 #endif
549   {"lgamma", lgammal, 8.0L, 8.525146484375L,
550    1.4876690414300165531036347125050759667737E-5L,
551    2.0156414779556099965363450527747404656959E0L, 4},
552   {"lgamma", lgammal, 0.125L, 2.0194091796875E0L,
553    9.1778662963453202905211670995899482809521E-6L,
554    -8.3884926632958548678027429230863429642684E0L, 4},
555   {"lgamma", lgammal, 0.375L, 8.63067626953125E-1L,
556    6.3553175224624050890941340154953324706293E-6L,
557    -2.7539990491451395757640192188045680759926E0L, 4},
558   {"lgamma", lgammal, 0.625L, 3.608245849609375E-1L,
559    4.9105280026811849576858227794878573691202E-6L,
560    -1.4527087645765665672107816120233772668729E0L, 4},
561   {"lgamma", lgammal, 0.875L, 8.5845947265625E-2L,
562    1.2759959709323502365583769487702269719126E-5L,
563    -8.0401707154769538232421854974614639758707E-1L, 4},
564   {"lgamma", lgammal, 1.0L, 0.0L,
565    0.0L, -5.7721566490153286060651209008240239144696E-1L, -4},
566   {"lgamma", lgammal, 1.125L, -6.0028076171875E-2L,
567    4.8920458354170685941567925698857217805491E-6L,
568    -3.8849266329585486780274292308634296426837E-1L, 4},
569   {"lgamma", lgammal, 1.375L, -1.17767333984375E-1L,
570    1.2063243296225548637966682011495753460784E-5L,
571    -8.7332382478472909097352552137901409325952E-2L, 4},
572   {"lgamma", lgammal, 1.625L, -1.091766357421875E-1L,
573    2.5019853921275340206546744374231564700714E-6L,
574    1.4729123542343343278921838797662273312715E-1L, 4},
575   {"lgamma", lgammal, 1.875L, -4.76837158203125E-2L,
576    1.1030421124200356021962838137727680303452E-5L,
577    3.3884007130944747481863859311099645955579E-1L, 4},
578   {"lgamma", lgammal, 2.375L, 2.0068359375E-1L,
579    1.4866627455841358885180272611091348667235E-5L,
580    6.3994034479425436362992017513482586340132E-1L, 4},
581   {"lgamma", lgammal, 2.75L, 4.752044677734375E-1L,
582    1.0199141499630313102466395428861742242065E-5L,
583    8.1890102497543259227787514194472409043081E-1L, 4},
584   {"lgamma", lgammal, 3.5L, 1.2009735107421875E0L,
585    9.1604886724816021881450712995770238915468E-8L,
586    1.1031566406452431872256903336679111259463E0L, 4},
587   {"lgamma", lgammal, 4.5L, 2.4537353515625E0L,
588    1.2192799422205041425034357161573318235107E-6L,
589    1.3888709263595289015114046193821968402320E0L, 4},
590   {"lgamma", lgammal, 5.5L, 3.9578094482421875E0L,
591    4.5193765287938774008558225909985513044920E-6L,
592    1.6110931485817511237336268416044190624542E0L, 4},
593   {"lgamma", lgammal, 6.5L, 5.6625518798828125E0L,
594    1.0179974329028522112312329543730297511212E-5L,
595    1.7929113303999329419154450234226008806361E0L, 4},
596   {"lgamma", lgammal, 7.5L, 7.53436279296875E0L,
597    1.4437899829551583676324366857670272790220E-6L,
598    1.9467574842460867880692911772687547267899E0L, 4},
599   {"lgamma", lgammal, 8.5L, 9.54925537109375E0L,
600    1.1886207247711737140081127222543124870800E-5L,
601    2.0800908175794201214026245106020880601232E0L, 4},
602   {"lgamma", lgammal, 9.5L, 1.16893310546875E1L,
603    2.3661097684825694425775421725106375736779E-6L,
604    2.1977378764029495331673303929550292365938E0L, 4},
605   {"lgamma", lgammal, 10.5L, 1.394061279296875E1L,
606    1.2426435013633161237887971849479799452805E-5L,
607    2.3030010342976863752725935508497660786991E0L, 4},
608   {"lgamma", lgammal, 11.5L, 1.62919921875E1L,
609    8.2890672413202446037468793783460085279579E-6L,
610    2.3982391295357816133678316460878613167943E0L, 4},
611   {"lgamma", lgammal, 12.5L, 1.8734344482421875E1L,
612    3.0295145707016341244572313978963754081384E-6L,
613    2.4851956512749120481504403417400352298378E0L, 4},
614   {"lgamma", lgammal, 13.5L, 2.126007080078125E1L,
615    5.3554634511414184110022255966073511107125E-6L,
616    2.5651956512749120481504403417400352298378E0, 4},
617   {"lgamma", lgammal, -0.5L,  1.2655029296875E0L,
618    9.1937971453964889457971347059238991475408E-6L,
619    3.6489973978576520559023667001244459279636E-2L, 4},
620   {"lgamma", lgammal, -1.5L, 8.6004638671875E-1L,
621    6.2865773101451093268167035678732715711736E-7L,
622    7.0315664064524318722569033366791112594630E-1L, 4},
623   {"lgamma", lgammal, -2.5L, -5.6243896484375E-2L,
624    1.7998670094932740546990234571587705589745E-7L,
625    1.1031566406452431872256903336679111259463E0L, -4},
626   {"lgamma", lgammal, -3.5L,-1.30902099609375E0L,
627    1.4311100707953639284847917342554315471302E-5L,
628    1.3888709263595289015114046193821968402320E0L, -4},
629   {"lgamma", lgammal, 1.0e18L, 4.0446531673037733888E19L,
630    8.5508840451951888057681732252156677289759E8L,
631    4.1446531673892822311823846184318555736736E1, 4},
632   {"tgamma", tgammal, 1.0L, 1.0L,
633    0.0L, -5.772156649015328606e-1L, 4},
634   {"tgamma", tgammal, 2.0L, 1.0L,
635    0.0L, 4.2278433509846713939e-1L, 4},
636   {"tgamma", tgammal, 3.0L, 2.0L,
637    0.0L, 1.845568670196934279L, 4},
638   {"tgamma", tgammal, 4.0L, 6.0L,
639    0.0L, 7.536706010590802836L, 4},
640   {NULL, NULL, 0.0L, 0.0L, 0.0L, 1},
641 };
642 
643 /* These take care of extra-precise floating point register problems.  */
644 static volatile long double volat1;
645 static volatile long double volat2;
646 
647 
648 /* Return the next nearest floating point value to X
649    in the direction of UPDOWN (+1 or -1).
650    (Might fail if X is denormalized.)  */
651 
652 static long double
nextval(x,updown)653 nextval (x, updown)
654      long double x;
655      int updown;
656 {
657   long double m;
658   int i;
659 
660   volat1 = x;
661   m = 0.25L * MACHEPL * volat1 * updown;
662   volat2 = volat1 + m;
663   if (volat2 != volat1)
664     printf ("successor failed\n");
665 
666   for (i = 2; i < 10; i++)
667     {
668       volat2 = volat1 + i * m;
669       if (volat1 != volat2)
670 	return volat2;
671     }
672 
673   printf ("nextval failed\n");
674   return volat1;
675 }
676 
677 
678 
679 
680 int
monotll()681 monotll ()
682 {
683   long double (*fun1) (long double);
684   int i, j, errs, tests, err_thresh;
685   long double x, x0, dy, err;
686 
687   errs = 0;
688   tests = 0;
689   i = 0;
690 
691   for (;;)
692     {
693       /* Function call reference.  */
694       fun1 = test1[i].func;
695       if (test1[i].name == NULL)
696 	break;
697       /*
698       if (fun1 == NULL)
699 	break;
700       */
701       /* Function argument.  */
702       volat1 = test1[i].arg1;
703       /* x0 is the given argument, x scans from slightly below to above x0. */
704       x0 = volat1;
705       x = volat1;
706       for (j = 0; j <= NPTS; j++)
707 	{
708 	  /* delta x */
709 	  volat1 = x - x0;
710 	  /* delta y */
711 	  dy = volat1 * test1[i].derivative;
712 	  /* y + delta y */
713 	  dy = test1[i].answer2 + dy;
714 	  volat1 = test1[i].answer1 + dy;
715 	  /* Run the function under test.  */
716 	  if (fun1 == NULL)
717 	    {
718 #if 0
719 	      if (! strcmp (test1[i].name, "jnl"))
720 		volat2 = jnl (3, x);
721 	      else
722 #endif
723 		break;
724 	    }
725 	  else
726 	    volat2 = (*(fun1)) (x);
727 	  if (volat2 != volat1)
728 	    {
729 	      /* Estimate difference between program result
730 		 and extended precision function value.  */
731 	      err = volat2 - test1[i].answer1;
732 	      err = err - dy;
733 	      /* Compare difference with reporting threshold.  */
734 	      err_thresh = test1[i].thresh;
735 	      if (err_thresh >= 0)
736 		err = err / volat1; /* relative error */
737 	      else
738 		{
739 		  err_thresh = -err_thresh; /* absolute error */
740 		  /* ...but relative error if function value > 1 */
741 		  if (fabsl(volat1) > 1.0L)
742 		    err = err / volat1;
743 		}
744 	      if (fabsl (err) > (err_thresh * MACHEPL))
745 		{
746 		  printf ("%d %s(%.36Le) = %.36Le, rel err = %.3Le\n",
747 			  j, test1[i].name, x, volat2, err);
748 		  errs += 1;
749 		}
750 	    }
751 	  x = nextval (x, 1);
752 	  tests += 1;
753 	}
754 
755       x = x0;
756       x = nextval (x, -1);
757       for (j = 1; j < NPTS; j++)
758 	{
759 	  volat1 = x - x0;
760 	  dy = volat1 * test1[i].derivative;
761 	  dy = test1[i].answer2 + dy;
762 	  volat1 = test1[i].answer1 + dy;
763 	  if (fun1 == NULL)
764 	    {
765 #if 0
766 	      if (! strcmp (test1[i].name, "jnl"))
767 		volat2 = jnl (3, x);
768 	      else
769 #endif
770 		break;
771 	    }
772 	  else
773 	    volat2 = (*(fun1)) (x);
774 	  if (volat2 != volat1)
775 	    {
776 	      err = volat2 - test1[i].answer1;
777 	      err = err - dy;
778 	      err_thresh = test1[i].thresh;
779 	      if (err_thresh >= 0)
780 		err = err / volat1; /* relative error */
781 	      else
782 		{
783 		  err_thresh = -err_thresh;
784 		  if (fabsl(volat1) > 1.0L)
785 		    err = err / volat1;
786 		}
787 	      if (fabsl (err) > (err_thresh * MACHEPL))
788 		{
789 		  printf ("%d %s(%.36Le) = %.36Le, rel err = %.3Le\n",
790 			  j, test1[i].name, x, volat2, err);
791 		  errs += 1;
792 		}
793 	    }
794 	  x = nextval (x, -1);
795 	  tests += 1;
796 	}
797       i += 1;
798     }
799   printf ("%d errors in %d tests\n", errs, tests);
800   return (errs);
801 }
802 #endif	/* LDBL_MANT_DIG == 113 */
803