summaryrefslogtreecommitdiff
path: root/usr/src/man/man3m/matherr.3m
blob: 07985f8232a08e310c6a210dcc7f6388150fb184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
'\" te
.\"  Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH MATHERR 3M "Sep 23, 1997" "SunOS 5.11" "Mathematical Library Functions"
.SH NAME
matherr \- math library exception-handling function
.SH SYNOPSIS
.LP
.nf
#include <math.h>

\fBint\fR \fBmatherr\fR(\fBstruct exception *\fR\fIexc\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The System V Interface Definition, Third Edition (SVID3) specifies that certain
\fBlibm\fR functions call \fBmatherr()\fR when exceptions are detected. Users
may define their own mechanisms for handling exceptions, by including a
function named \fBmatherr()\fR in their programs. The \fBmatherr()\fR function
is of the form described above. When an exception occurs, a pointer to the
exception structure \fIexc\fR will be passed to the user-supplied
\fBmatherr()\fR function.  This structure, which is defined in the
\fB<math.h>\fR header file, is as follows:
.sp
.in +2
.nf
struct exception {
	int type;
	char *name;
	double arg1, arg2, retval;
};
.fi
.in -2

.sp
.LP
The \fBtype\fR member is an integer describing the type of exception that has
occurred, from the following list of constants (defined in the header file):
.sp
.ne 2
.mk
.na
\fB\fBDOMAIN\fR\fR
.ad
.RS 13n
.rt
argument domain exception
.RE

.sp
.ne 2
.mk
.na
\fB\fBSING\fR\fR
.ad
.RS 13n
.rt
argument singularity
.RE

.sp
.ne 2
.mk
.na
\fB\fBOVERFLOW\fR\fR
.ad
.RS 13n
.rt
overflow range exception
.RE

.sp
.ne 2
.mk
.na
\fB\fBUNDERFLOW\fR\fR
.ad
.RS 13n
.rt
underflow range exception
.RE

.sp
.ne 2
.mk
.na
\fB\fBTLOSS\fR\fR
.ad
.RS 13n
.rt
total loss of significance
.RE

.sp
.ne 2
.mk
.na
\fB\fBPLOSS\fR\fR
.ad
.RS 13n
.rt
partial loss of significance
.RE

.sp
.LP
Both \fBTLOSS\fR and \fBPLOSS\fR reflect limitations of particular algorithms
for trigonometric functions that suffer abrupt declines in accuracy at definite
boundaries. Since the implementation does not suffer such abrupt declines,
\fBPLOSS\fR is never signaled. \fBTLOSS\fR is signaled for Bessel functions
\fIonly\fR to satisfy SVID3 requirements.
.sp
.LP
The \fBname\fR member points to a string containing the name of the function
that incurred the exception. The \fBarg1\fR and \fBarg2\fR members are the
arguments with which the function was invoked. \fBretval\fR is set to the
default value that will be returned by the function unless the user's
\fBmatherr()\fR sets it to a different value.
.sp
.LP
If the user's \fBmatherr()\fR function returns non-zero, no exception message
will be printed and \fBerrno\fR is not set.
.SH SVID3 STANDARD CONFORMANCE
.sp
.LP
When an application is built as a SVID3 conforming application (see
\fBstandards\fR(5)), if \fBmatherr()\fR is not supplied by the user, the
default matherr exception-handling mechanisms, summarized in the table below,
are invoked upon exception:
.sp
.ne 2
.mk
.na
\fB\fBDOMAIN\fR\fR
.ad
.RS 13n
.rt
0.0 is usually returned, \fBerrno\fR is set to \fBEDOM\fR and a message is
usually printed on standard error.
.RE

.sp
.ne 2
.mk
.na
\fB\fBSING\fR\fR
.ad
.RS 13n
.rt
The largest finite single-precision number, \fBHUGE\fR of appropriate sign, is
returned, \fBerrno\fR is set to \fBEDOM\fR, and a message is printed on
standard error.
.RE

.sp
.ne 2
.mk
.na
\fB\fBOVERFLOW\fR\fR
.ad
.RS 13n
.rt
The largest finite single-precision number, \fBHUGE\fR of appropriate sign, is
usually returned and \fBerrno\fR is set to \fBERANGE\fR.
.RE

.sp
.ne 2
.mk
.na
\fB\fBUNDERFLOW\fR\fR
.ad
.RS 13n
.rt
0.0 is returned and \fBerrno\fR is set to \fBERANGE\fR.
.RE

.sp
.ne 2
.mk
.na
\fB\fBTLOSS\fR\fR
.ad
.RS 13n
.rt
0.0 is returned, \fBerrno\fR is set to \fBERANGE\fR, and a message is printed
on standard error.
.RE

.sp
.LP
In general, \fBerrno\fR is not a reliable error indicator because it can be
unexpectedly set by a function in a handler for an asynchronous signal.
.SS "SVID3 ERROR HANDLING PROCEDURES (compile with cc \e-Xt)"
.sp

.sp
.TS
tab(	) box;
cw(1.29i) |cw(.81i) |cw(.79i) |cw(.87i) |cw(1.03i) |cw(.71i)
lw(1.29i) |lw(.81i) |lw(.79i) |lw(.87i) |lw(1.03i) |lw(.71i)
.
<math.h> type	DOMAIN	SING	OVERFLOW	UNDERFLOW	TLOSS
_
\fBerrno\fR	EDOM	EDOM	ERANGE	ERANGE	ERANGE
_
IEEE Exception	Invalid Operation	Division by Zero	Overflow	Underflow	\(mi
_
fp_exception_type	fp_invalid	fp_division	fp_overflow	fp_underflow	\(mi
_
ACOS, ASIN\|(|x| > 1):	Md, 0.0	\(mi	\(mi	\(mi	\(mi
_
ACOSH\|(x < 1), ATANH\|(|x| > 1):	NaN	\(mi	\(mi	\(mi	\(mi
_
ATAN2\|(0,0):	Md, 0.0	\(mi	\(mi	\(mi	\(mi
_
COSH, SINH:	\(mi	\(mi	\(+-HUGE	\(mi	\(mi
_
EXP:	\(mi	\(mi	+HUGE	0.0	\(mi
_
FMOD\|(x,0):	x	\(mi	\(mi	\(mi	\(mi
_
HYPOT:	\(mi	\(mi	+HUGE	\(mi	\(mi
_
J0, J1, JN\|(|x| > X_TLOSS):	\(mi	\(mi	\(mi	\(mi	Mt, 0.0
_
LGAMMA:
 usual cases	\(mi	\(mi	+HUGE	\(mi	\(mi
 (x = 0 or \(miinteger)	\(mi	Ms, +HUGE	\(mi	\(mi	\(mi
_
LOG, LOG10:
 (x < 0)	Md, \(miHUGE	\(mi	 \(mi	\(mi	\(mi
 (x = 0)	\(mi	Ms, \(miHUGE	\(mi	\(mi	\(mi
_
POW:
 usual cases	\(mi	\(mi	\(+-HUGE	\(+-0.0	\(mi
 (x < 0) ** (y not an integer)	Md, 0.0	\(mi	\(mi	\(mi	\(mi
 0 ** 0	Md, 0.0	\(mi	\(mi	\(mi	\(mi
 0 ** (y < 0)	Md, 0.0	\(mi	\(mi	\(mi
_
REMAINDER\|(x,0):	NaN	\(mi	\(mi	\(mi	\(mi
_
SCALB:	\(mi	\(mi	\(+-HUGE_VAL	\(+-0.0	\(mi
_
SQRT\|(x < 0):	Md, 0.0	\(mi	\(mi	\(mi	\(mi
_
Y0, Y1, YN:
 (x < 0)	Md, \(miHUGE	\(mi	\(mi	\(mi	\(mi
 (x = 0)	\(mi	Md, \(miHUGE	\(mi	\(mi	\(mi
 (x > X_TLOSS)	\(mi	\(mi	\(mi	\(mi	Mt, 0.0
.TE

.SS "Abbreviations"
.sp
.ne 2
.mk
.na
\fBMd\fR
.ad
.RS 12n
.rt
Message is printed (DOMAIN error).
.RE

.sp
.ne 2
.mk
.na
\fBMs\fR
.ad
.RS 12n
.rt
Message is printed (SING error).
.RE

.sp
.ne 2
.mk
.na
\fBMt\fR
.ad
.RS 12n
.rt
Message is printed (TLOSS error).
.RE

.sp
.ne 2
.mk
.na
\fBNaN\fR
.ad
.RS 12n
.rt
IEEE NaN result and invalid operation exception.
.RE

.sp
.ne 2
.mk
.na
\fBHUGE\fR
.ad
.RS 12n
.rt
Maximum finite single-precision floating-point number.
.RE

.sp
.ne 2
.mk
.na
\fBHUGE_VAL\fR
.ad
.RS 12n
.rt
IEEE \(if result and division-by-zero exception.
.RE

.sp
.ne 2
.mk
.na
\fBX_TLOSS\fR
.ad
.RS 12n
.rt
The value X_TLOSS is defined in <values.h>.
.RE

.sp
.LP
The interaction of IEEE arithmetic and \fBmatherr()\fR is not defined when
executing under IEEE rounding modes other than the default round to nearest:
\fBmatherr()\fR is not always called on overflow or underflow and can return
results that differ from those in this table.
.SH X/OPEN COMMON APPLICATION ENVIRONMENT (CAE) SPECIFICATIONS CONFORMANCE
.sp
.LP
The X/Open System Interfaces and Headers (XSH) Issue 3 and later revisions of
that specification no longer sanctions the use of the \fBmatherr\fR interface.
The following table summarizes the values returned in the exceptional cases.
In general, XSH dictates that as long as one of the input argument(s) is a NaN,
NaN is returned. In particular, \fBpow(NaN,0)\fR = NaN.
.SS "CAE SPECIFICATION ERROR HANDLING PROCEDURES (compile with cc \fB-Xa\fR)"
.sp

.sp
.TS
tab(	) box;
cw(.82i) |cw(1.03i) |cw(1i) |cw(.97i) |cw(.96i) |cw(.72i)
lw(.82i) |lw(1.03i) |lw(1i) |lw(.97i) |lw(.96i) |lw(.72i)
.
<math.h> type	DOMAIN	SING	OVERFLOW	UNDERFLOW	TLOSS
_
\fBerrno\fR	EDOM	EDOM	ERANGE	ERANGE	ERANGE
_
ACOS, ASIN\|(|x| > 1):	0.0	\(mi	\(mi	\(mi	\(mi
_
ATAN2\|(0,0):	0.0	\(mi	\(mi	\(mi	\(mi
_
COSH, SINH:	\(mi	\(mi	{\(+-HUGE_VAL}	\(mi	\(mi
_
EXP:	\(mi	\(mi	{+HUGE_VAL}	{0.0}	\(mi
_
FMOD\|(x,0):	{NaN}	\(mi	\(mi	\(mi	\(mi
_
HYPOT:	\(mi	\(mi	{+HUGE_VAL}	\(mi	\(mi
_
J0, J1, JN\|(|x| > X_TLOSS):	\(mi	\(mi	\(mi	\(mi	{0.0}
_
LGAMMA:
 usual cases	\(mi	\(mi	{+HUGE_VAL}	\(mi	\(mi
 (x = 0 or \(miinteger)	\(mi	+HUGE_VAL	\(mi	\(mi	\(mi
_
LOG, LOG10:
 (x < 0)	\fB-HUGE_VAL\fR	\(mi	\(mi	\(mi	\(mi
 (x = 0)	\(mi	\fB-HUGE_VAL\fR	\(mi	\(mi	\(mi
_
POW:
 usual cases	\(mi	\(mi	\(+-HUGE_VAL	\(+-0.0	\(mi
 (x < 0) ** (y not an integer)	0.0	\(mi	\(mi	\(mi	\(mi
 0 ** 0	{1.0}	\(mi	\(mi	\(mi	\(mi
 0 ** (y < 0)	{\fB-HUGE_VAL\fR}	\(mi	\(mi	\(mi	\(mi
_
SQRT\|(x < 0):	0.0	\(mi	\(mi	\(mi	\(mi
_
Y0, Y1, YN:
 (x < 0)	{\fB-HUGE_VAL\fR}	\(mi	\(mi	\(mi	\(mi
 (x = 0)	\(mi	{\fB-HUGE_VAL\fR}	\(mi	\(mi	\(mi
 (x > X_TLOSS)	\(mi	\(mi	\(mi	\(mi	0.0
.TE

.SS "Abbreviations"
.sp
.ne 2
.mk
.na
\fB{...}\fR
.ad
.RS 12n
.rt
\fBerrno\fR is not to be relied upon in all braced cases.
.RE

.sp
.ne 2
.mk
.na
\fBNaN\fR
.ad
.RS 12n
.rt
IEEE NaN result and invalid operation exception.
.RE

.sp
.ne 2
.mk
.na
\fBHUGE_VAL\fR
.ad
.RS 12n
.rt
IEEE \(if result and division-by-zero exception.
.RE

.sp
.ne 2
.mk
.na
\fBX_TLOSS\fR
.ad
.RS 12n
.rt
The value X_TLOSS is defined in <\fBvalues.h\fR>.
.RE

.SH ANSI/ISO-C STANDARD CONFORMANCE
.sp
.LP
The ANSI/ISO-C standard covers a small subset of the CAE specification.
.sp
.LP
The following table summarizes the values returned in the exceptional cases.
.SS "ANSI/ISO-C ERROR HANDLING PROCEDURES (compile with cc \fB-Xc\fR)"
.sp

.sp
.TS
tab(	) box;
cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.11i)
lw(1.1i) |lw(1.1i) |lw(1.1i) |lw(1.1i) |lw(1.11i)
.
<math.h> type	DOMAIN	SING	OVERFLOW	UNDERFLOW
_
\fBerrno\fR	EDOM	EDOM	ERANGE	ERANGE
_
ACOS, ASIN\|(|x| > 1):	0.0	\(mi	\(mi	\(mi
_
ATAN2\|(0,0):	0.0	\(mi	\(mi	\(mi
_
EXP:	\(mi	\(mi	+HUGE_VAL	0.0
_
FMOD\|(x,0):	NaN	\(mi	\(mi	\(mi
_
LOG, LOG10:
 (x < 0)	\fB-HUGE_VAL\fR	\(mi	\(mi	\(mi
 (x = 0)	\(mi	\fB-HUGE_VAL\fR	\(mi	\(mi
_
POW:
 usual cases	\(mi	\(mi	\(+-HUGE_VAL	\(+-0.0
 (x < 0) ** (y not an integer)	0.0	\(mi	\(mi	\(mi
 0 ** (y < 0)	\fB-HUGE_VAL\fR	\(mi	\(mi	\(mi
_
SQRT\|(x < 0):	0.0	\(mi	\(mi	\(mi
.TE

.SS "ABBREVIATIONS"
.sp
.ne 2
.mk
.na
\fBNaN\fR
.ad
.RS 12n
.rt
IEEE NaN result and invalid operation exception.
.RE

.sp
.ne 2
.mk
.na
\fBHUGE_VAL\fR
.ad
.RS 12n
.rt
IEEE \(if result and division-by-zero.
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRExample of \fBmatherr()\fR function
.sp
.in +2
.nf
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int
matherr(struct exception *x) {
    switch (x\(mi>type) {
        case DOMAIN:
            /* change sqrt to return sqrt(\(miarg1), not NaN */
   if (!strcmp(x\(mi>name, "sqrt")) {
    x\(mi>retval = sqrt(\(mix\(mi>arg1);
    return (0); /* print message and set errno */
   } /* FALLTHRU */
  case SING:
   /* all other domain or sing exceptions, print message and */
   /* abort */
   fprintf(stderr, "domain exception in %s\en", x\(mi>name);
   abort( );
   break;
  }
  return (0); /* all other exceptions, execute default procedure */
 }
.fi
.in -2

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
tab(	) box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
\fBattributes\fR(5), \fBstandards\fR(5)