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
7bcfb67f
Commit
7bcfb67f
authored
May 16, 2012
by
Paolo Bosetti
Browse files
Options
Browse Files
Download
Plain Diff
Merged MSVC branch
parents
aee20de2
b9b20c8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
21 deletions
+30
-21
src/math.c
src/math.c
+30
-21
No files found.
src/math.c
View file @
7bcfb67f
...
@@ -17,6 +17,10 @@
...
@@ -17,6 +17,10 @@
#define atanh(x) (log(1+x) - log(1-x))/2.0
#define atanh(x) (log(1+x) - log(1-x))/2.0
#define cbrt(x) pow(x,1.0/3.0)
#define cbrt(x) pow(x,1.0/3.0)
/* Declaration of complementary Error function */
double
erfc
(
double
x
);
/*
/*
** Implementations of error functions
** Implementations of error functions
** credits to http://www.digitalmars.com/archives/cplusplus/3634.html
** credits to http://www.digitalmars.com/archives/cplusplus/3634.html
...
@@ -26,18 +30,20 @@
...
@@ -26,18 +30,20 @@
double
double
erf
(
double
x
)
erf
(
double
x
)
{
{
static
const
double
two_sqrtpi
=
1
.
128379167095512574
;
static
const
double
two_sqrtpi
=
1
.
128379167095512574
;
double
sum
=
x
;
double
term
=
x
;
double
xsqr
=
x
*
x
;
int
j
=
1
;
if
(
fabs
(
x
)
>
2
.
2
)
{
if
(
fabs
(
x
)
>
2
.
2
)
{
return
1
.
0
-
erfc
(
x
);
return
1
.
0
-
erfc
(
x
);
}
}
double
sum
=
x
,
term
=
x
,
xsqr
=
x
*
x
;
int
j
=
1
;
do
{
do
{
term
*=
xsqr
/
j
;
term
*=
xsqr
/
j
;
sum
-=
term
/
(
2
*
j
+
1
);
sum
-=
term
/
(
2
*
j
+
1
);
++
j
;
++
j
;
term
*=
xsqr
/
j
;
term
*=
xsqr
/
j
;
sum
+=
term
/
(
2
*
j
+
1
);
sum
+=
term
/
(
2
*
j
+
1
);
++
j
;
++
j
;
}
while
(
fabs
(
term
)
/
sum
>
REL_ERROR
);
}
while
(
fabs
(
term
)
/
sum
>
REL_ERROR
);
return
two_sqrtpi
*
sum
;
return
two_sqrtpi
*
sum
;
...
@@ -48,26 +54,29 @@ double
...
@@ -48,26 +54,29 @@ double
erfc
(
double
x
)
erfc
(
double
x
)
{
{
static
const
double
one_sqrtpi
=
0
.
564189583547756287
;
static
const
double
one_sqrtpi
=
0
.
564189583547756287
;
double
a
=
1
;
double
b
=
x
;
double
c
=
x
;
double
d
=
x
*
x
+
0
.
5
;
double
q1
,
q2
;
double
n
=
1
.
0
;
double
t
;
if
(
fabs
(
x
)
<
2
.
2
)
{
if
(
fabs
(
x
)
<
2
.
2
)
{
return
1
.
0
-
erf
(
x
);
return
1
.
0
-
erf
(
x
);
}
}
if
(
signbit
(
x
))
{
if
(
x
<
0
.
0
)
{
/*signbit(x)*/
return
2
.
0
-
erfc
(
-
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
{
do
{
t
=
a
*
n
+
b
*
x
;
t
=
a
*
n
+
b
*
x
;
a
=
b
;
a
=
b
;
b
=
t
;
b
=
t
;
t
=
c
*
n
+
d
*
x
;
t
=
c
*
n
+
d
*
x
;
c
=
d
;
c
=
d
;
d
=
t
;
d
=
t
;
n
+=
0
.
5
;
n
+=
0
.
5
;
q1
=
q2
;
q1
=
q2
;
q2
=
b
/
d
;
q2
=
b
/
d
;
}
while
(
fabs
(
q1
-
q2
)
/
q2
>
REL_ERROR
);
}
while
(
fabs
(
q1
-
q2
)
/
q2
>
REL_ERROR
);
return
one_sqrtpi
*
exp
(
-
x
*
x
)
*
q2
;
return
one_sqrtpi
*
exp
(
-
x
*
x
)
*
q2
;
}
}
...
...
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