xref: /reactos/sdk/lib/crt/math/_invoke_matherr.c (revision 09dde2cf)
1 /*
2  * PROJECT:     ReactOS CRT library
3  * LICENSE:     MIT (https://spdx.org/licenses/MIT)
4  * PURPOSE:     Implementation of _invoke_matherr and __setusermatherr
5  * COPYRIGHT:   Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6  */
7 
8 #include <math.h>
9 
10 /* MS headers have this in corecrt_startup.h */
11 typedef int (*_UserMathErrorFunctionPointer)(struct _exception *);
12 
13 static _UserMathErrorFunctionPointer user_matherr = NULL;;
14 
15 void
16 __cdecl
17 __setusermatherr(_UserMathErrorFunctionPointer func)
18 {
19     user_matherr = func;
20 }
21 
22 int
23 __cdecl
24 _invoke_matherr(
25     int type,
26     char* name,
27     double arg1,
28     double arg2,
29     double retval)
30 {
31     if (user_matherr != NULL)
32     {
33         struct _exception excpt;
34         excpt.type = type;
35         excpt.name = name;
36         excpt.arg1 = arg1;
37         excpt.arg2 = arg2;
38         excpt.retval = retval;
39         return user_matherr(&excpt);
40     }
41     else
42     {
43         return 0;
44     }
45 }
46