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
8ecd38d6
Unverified
Commit
8ecd38d6
authored
Feb 06, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reimplement complex division.
parent
ea0737ec
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
7 deletions
+21
-7
mrbgems/mruby-cmath/src/cmath.c
mrbgems/mruby-cmath/src/cmath.c
+21
-7
No files found.
mrbgems/mruby-cmath/src/cmath.c
View file @
8ecd38d6
...
@@ -55,11 +55,9 @@ cmath_get_complex(mrb_state *mrb, mrb_value c, mrb_float *r, mrb_float *i)
...
@@ -55,11 +55,9 @@ cmath_get_complex(mrb_state *mrb, mrb_value c, mrb_float *r, mrb_float *i)
#ifdef MRB_USE_FLOAT32
#ifdef MRB_USE_FLOAT32
typedef
_Fcomplex
mrb_complex
;
typedef
_Fcomplex
mrb_complex
;
#define CX(r,i) _FCbuild(r,i)
#define CX(r,i) _FCbuild(r,i)
#define CXMUL(x,y) _FCmulcr(x,y)
#else
#else
typedef
_Dcomplex
mrb_complex
;
typedef
_Dcomplex
mrb_complex
;
#define CX(r,i) _Cbuild(r,i)
#define CX(r,i) _Cbuild(r,i)
#define CXMUL(x,y) _Cmulcr(x,y)
#endif
#endif
static
mrb_complex
static
mrb_complex
...
@@ -69,12 +67,28 @@ CXDIVf(mrb_complex x, mrb_float y)
...
@@ -69,12 +67,28 @@ CXDIVf(mrb_complex x, mrb_float y)
}
}
static
mrb_complex
static
mrb_complex
CXDIVc
(
mrb_complex
x
,
mrb_complex
y
)
CXDIVc
(
mrb_complex
a
,
mrb_complex
b
)
{
{
mrb_complex
n
=
CXMUL
(
x
,
F
(
conj
)(
y
));
mrb_float
ratio
,
den
;
mrb_complex
d
=
_CXMUL
(
y
,
F
(
conj
)(
y
));
mrb_float
abr
,
abi
,
cr
,
ci
;
return
CX
(
creal
(
n
)
/
creal
(
d
),
cimag
(
n
)
/
cimag
(
d
));
if
((
abr
=
creal
(
b
))
<
0
)
abr
=
-
abr
;
if
((
abi
=
cimag
(
b
))
<
0
)
abi
=
-
abi
;
if
(
abr
<=
abi
)
{
ratio
=
creal
(
b
)
/
cimag
(
b
)
;
den
=
cimag
(
a
)
*
(
1
+
ratio
*
ratio
);
cr
=
(
creal
(
a
)
*
ratio
+
cimag
(
a
))
/
den
;
ci
=
(
cimag
(
a
)
*
ratio
-
creal
(
a
))
/
den
;
}
else
{
ratio
=
cimag
(
b
)
/
creal
(
b
)
;
den
=
creal
(
a
)
*
(
1
+
ratio
*
ratio
);
cr
=
(
creal
(
a
)
+
cimag
(
a
)
*
ratio
)
/
den
;
ci
=
(
cimag
(
a
)
-
creal
(
a
)
*
ratio
)
/
den
;
}
return
CX
(
cr
,
ci
);
}
}
#else
#else
...
...
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