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
88113df0
Unverified
Commit
88113df0
authored
Feb 06, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed compile errors in `cmath.c` in MinGW and macOS.
parent
2a69f510
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
9 deletions
+31
-9
mrbgems/mruby-cmath/src/cmath.c
mrbgems/mruby-cmath/src/cmath.c
+31
-9
No files found.
mrbgems/mruby-cmath/src/cmath.c
View file @
88113df0
...
...
@@ -91,18 +91,40 @@ CXDIVc(mrb_complex a, mrb_complex b)
return
CX
(
cr
,
ci
);
}
#else
#if defined(__cplusplus) && defined(__APPLE__)
#ifdef MRB_USE_FLOAT32
typedef
std
::
complex
<
float
>
mrb_complex
;
#else
typedef
std
::
complex
<
double
>
mrb_complex
;
#endif
/* MRB_USE_FLOAT32 */
#define CX(r,i) mrb_complex(r,i)
#define creal(c) c.real()
#define cimag(c) c.imag()
#define FC(n) F(n)
#else
/* cpp */
#ifdef MRB_USE_FLOAT32
typedef
float
_Complex
mrb_complex
;
#else
typedef
double
_Complex
mrb_complex
;
#endif
/* MRB_USE_FLOAT32 */
#define CX(r,i) ((r)+(i)*_Complex_I)
#endif
#define CX(r,i) (r+i*I)
#define CXDIVf(x,y) (x)/(y)
#define CXDIVc(x,y) (x)/(y)
#endif
#ifndef FC
#define FC(n) F(c ## n)
#endif
#define DEF_CMATH_METHOD(name) \
...
...
@@ -113,7 +135,7 @@ cmath_ ## name(mrb_state *mrb, mrb_value self)\
mrb_float real, imag;\
if (cmath_get_complex(mrb, z, &real, &imag)) {\
mrb_complex c = CX(real,imag);\
c = F
(c ##
name)(c);\
c = F
C(
name)(c);\
return mrb_complex_new(mrb, creal(c), cimag(c));\
}\
return mrb_float_value(mrb, F(name)(real));\
...
...
@@ -138,8 +160,8 @@ cmath_log(mrb_state *mrb, mrb_value self) {
if
(
n
==
1
)
base
=
M_E
;
if
(
cmath_get_complex
(
mrb
,
z
,
&
real
,
&
imag
)
||
real
<
0
.
0
)
{
mrb_complex
c
=
CX
(
real
,
imag
);
c
=
F
(
c
log
)(
c
);
if
(
n
==
2
)
c
=
CXDIVc
(
c
,
F
(
c
log
)(
CX
(
base
,
0
)));
c
=
F
C
(
log
)(
c
);
if
(
n
==
2
)
c
=
CXDIVc
(
c
,
F
C
(
log
)(
CX
(
base
,
0
)));
return
mrb_complex_new
(
mrb
,
creal
(
c
),
cimag
(
c
));
}
if
(
n
==
1
)
return
mrb_float_value
(
mrb
,
F
(
log
)(
real
));
...
...
@@ -153,7 +175,7 @@ cmath_log10(mrb_state *mrb, mrb_value self) {
mrb_float
real
,
imag
;
if
(
cmath_get_complex
(
mrb
,
z
,
&
real
,
&
imag
)
||
real
<
0
.
0
)
{
mrb_complex
c
=
CX
(
real
,
imag
);
c
=
CXDIVf
(
F
(
c
log
)(
c
),
log
(
10
));
c
=
CXDIVf
(
F
C
(
log
)(
c
),
log
(
10
));
return
mrb_complex_new
(
mrb
,
creal
(
c
),
cimag
(
c
));
}
return
mrb_float_value
(
mrb
,
F
(
log10
)(
real
));
...
...
@@ -166,7 +188,7 @@ cmath_log2(mrb_state *mrb, mrb_value self) {
mrb_float
real
,
imag
;
if
(
cmath_get_complex
(
mrb
,
z
,
&
real
,
&
imag
)
||
real
<
0
.
0
)
{
mrb_complex
c
=
CX
(
real
,
imag
);
c
=
CXDIVf
(
F
(
clog
)(
c
),
log
(
2
));
c
=
CXDIVf
(
F
C
(
log
)(
c
),
log
(
2
.
0
));
return
mrb_complex_new
(
mrb
,
creal
(
c
),
cimag
(
c
));
}
return
mrb_float_value
(
mrb
,
F
(
log2
)(
real
));
...
...
@@ -179,7 +201,7 @@ cmath_sqrt(mrb_state *mrb, mrb_value self) {
mrb_float
real
,
imag
;
if
(
cmath_get_complex
(
mrb
,
z
,
&
real
,
&
imag
)
||
real
<
0
.
0
)
{
mrb_complex
c
=
CX
(
real
,
imag
);
c
=
F
(
c
sqrt
)(
c
);
c
=
F
C
(
sqrt
)(
c
);
return
mrb_complex_new
(
mrb
,
creal
(
c
),
cimag
(
c
));
}
return
mrb_float_value
(
mrb
,
F
(
sqrt
)(
real
));
...
...
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