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
98a95530
Commit
98a95530
authored
Aug 16, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2537 from chasonr/math-functions
Improve replacement math functions for Visual C++.
parents
47ab5138
e23deaaf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
4 deletions
+68
-4
mrbgems/mruby-math/src/math.c
mrbgems/mruby-math/src/math.c
+68
-4
No files found.
mrbgems/mruby-math/src/math.c
View file @
98a95530
...
...
@@ -23,10 +23,74 @@ domain_error(mrb_state *mrb, const char *func)
#define MATH_TOLERANCE 1E-12
#define asinh(x) log(x + sqrt(pow(x,2.0) + 1))
#define acosh(x) log(x + sqrt(pow(x,2.0) - 1))
#define atanh(x) (log(1+x) - log(1-x))/2.0
#define cbrt(x) pow(x,1.0/3.0)
double
asinh
(
double
x
)
{
double
xa
,
ya
,
y
;
/* Basic formula loses precision for x < 0, but asinh is an odd function */
xa
=
fabs
(
x
);
if
(
xa
>
3.16227E+18
)
{
/* Prevent x*x from overflowing; basic formula reduces to log(2*x) */
ya
=
log
(
xa
)
+
0
.
69314718055994530942
;
}
else
{
/* Basic formula for asinh */
ya
=
log
(
xa
+
sqrt
(
xa
*
xa
+
1
.
0
));
}
y
=
copysign
(
ya
,
x
);
return
y
;
}
double
acosh
(
double
x
)
{
double
y
;
if
(
x
>
3.16227E+18
)
{
/* Prevent x*x from overflowing; basic formula reduces to log(2*x) */
y
=
log
(
x
)
+
0
.
69314718055994530942
;
}
else
{
/* Basic formula for acosh */
y
=
log
(
x
+
sqrt
(
x
*
x
-
1
.
0
));
}
return
y
;
}
double
atanh
(
double
x
)
{
double
y
;
if
(
fabs
(
x
)
<
1E-2
)
{
/* The sums 1+x and 1-x lose precision for small x. Use the polynomial
instead. */
double
x2
=
x
*
x
;
y
=
x
*
(
1
.
0
+
x2
*
(
1
.
0
/
3
.
0
+
x2
*
(
1
.
0
/
5
.
0
+
x2
*
(
1
.
0
/
7
.
0
))));
}
else
{
/* Basic formula for atanh */
y
=
0
.
5
*
(
log
(
1
.
0
+
x
)
-
log
(
1
.
0
-
x
));
}
return
y
;
}
double
cbrt
(
double
x
)
{
double
xa
,
ya
,
y
;
/* pow(x, y) is undefined for x < 0 and y not an integer, but cbrt is an
odd function */
xa
=
fabs
(
x
);
ya
=
pow
(
xa
,
1
.
0
/
3
.
0
);
y
=
copysign
(
ya
,
x
);
return
y
;
}
/* Declaration of complementary Error function */
double
...
...
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