Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
2948a96c
Commit
2948a96c
authored
May 15, 2012
by
Paolo Bosetti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added also support for erfc under MSVC
parent
7da51a9d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
24 deletions
+47
-24
src/math.c
src/math.c
+47
-24
No files found.
src/math.c
View file @
2948a96c
...
...
@@ -17,28 +17,55 @@
#define atanh(x) (log(1+x) - log(1-x))/2.0
#define cbrt(x) pow(x,1.0/3.0)
#define REL_ERROR 1E-12
/* Implementation of Error function */
double
erf
(
double
x
)
{
static
const
double
two_sqrtpi
=
1
.
128379167095512574
;
if
(
fabs
(
x
)
>
2
.
2
)
{
return
1
.
0
-
erfc
(
x
);
}
double
sum
=
x
,
term
=
x
,
xsqr
=
x
*
x
;
int
j
=
1
;
do
{
term
*=
xsqr
/
j
;
sum
-=
term
/
(
2
*
j
+
1
);
++
j
;
term
*=
xsqr
/
j
;
sum
+=
term
/
(
2
*
j
+
1
);
++
j
;
}
while
(
fabs
(
term
)
/
sum
>
REL_ERROR
);
return
two_sqrtpi
*
sum
;
}
double
erf
(
double
x
)
/* Implementation of complementary Error function */
double
erfc
(
double
x
)
{
// constants
double
a1
=
0
.
254829592
;
double
a2
=
-
0
.
284496736
;
double
a3
=
1
.
421413741
;
double
a4
=
-
1
.
453152027
;
double
a5
=
1
.
06140542
9
;
double
p
=
0
.
3275911
;
// Save the sign of x
int
sign
=
1
;
if
(
x
<
0
)
sign
=
-
1
;
x
=
fabs
(
x
);
// A&S formula 7.1.26
double
t
=
1
.
0
/
(
1
.
0
+
p
*
x
);
double
y
=
1
.
0
-
(((((
a5
*
t
+
a4
)
*
t
)
+
a3
)
*
t
+
a2
)
*
t
+
a1
)
*
t
*
exp
(
-
x
*
x
);
return
sign
*
y
;
static
const
double
one_sqrtpi
=
0
.
564189583547756287
;
if
(
fabs
(
x
)
<
2
.
2
)
{
return
1
.
0
-
erf
(
x
);
}
if
(
signbit
(
x
))
{
return
2
.
0
-
erfc
(
-
x
);
}
double
a
=
1
,
b
=
x
;
double
c
=
x
,
d
=
x
*
x
+
0
.
5
;
double
q1
,
q2
;
double
n
=
1
.
0
,
t
;
do
{
t
=
a
*
n
+
b
*
x
;
a
=
b
;
b
=
t
;
t
=
c
*
n
+
d
*
x
;
c
=
d
;
d
=
t
;
n
+=
0
.
5
;
q1
=
q2
;
q2
=
b
/
d
;
}
while
(
fabs
(
q1
-
q2
)
/
q2
>
REL_ERROR
);
return
one_sqrtpi
*
exp
(
-
x
*
x
)
*
q2
;
}
#endif
...
...
@@ -546,7 +573,6 @@ math_erf(mrb_state *mrb, mrb_value obj)
}
#ifndef _MSC_VER
/*
* call-seq:
* Math.erfc(x) -> float
...
...
@@ -563,7 +589,6 @@ math_erfc(mrb_state *mrb, mrb_value obj)
return
mrb_float_value
(
x
);
}
#endif
/* ------------------------------------------------------------------------*/
void
...
...
@@ -613,7 +638,5 @@ mrb_init_math(mrb_state *mrb)
mrb_define_class_method
(
mrb
,
mrb_math
,
"hypot"
,
math_hypot
,
2
);
mrb_define_class_method
(
mrb
,
mrb_math
,
"erf"
,
math_erf
,
1
);
#ifndef _MSC_VER
mrb_define_class_method
(
mrb
,
mrb_math
,
"erfc"
,
math_erfc
,
1
);
#endif
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment