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
c181d1e7
Commit
c181d1e7
authored
Aug 08, 2019
by
Ray Chason
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Complex#abs in terms of Math.hypot
Math.hypot avoids premature overflow and underflow
parent
438638b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
1 deletion
+9
-1
mrbgems/mruby-complex/mrblib/complex.rb
mrbgems/mruby-complex/mrblib/complex.rb
+1
-1
mrbgems/mruby-complex/test/complex.rb
mrbgems/mruby-complex/test/complex.rb
+8
-0
No files found.
mrbgems/mruby-complex/mrblib/complex.rb
View file @
c181d1e7
...
@@ -62,7 +62,7 @@ class Complex < Numeric
...
@@ -62,7 +62,7 @@ class Complex < Numeric
end
end
def
abs
def
abs
Math
.
sqrt
(
abs2
)
Math
.
hypot
imaginary
,
real
end
end
alias_method
:magnitude
,
:abs
alias_method
:magnitude
,
:abs
...
...
mrbgems/mruby-complex/test/complex.rb
View file @
c181d1e7
...
@@ -70,6 +70,14 @@ end
...
@@ -70,6 +70,14 @@ end
assert
'Complex#abs'
do
assert
'Complex#abs'
do
assert_float
Complex
(
-
1
).
abs
,
1
assert_float
Complex
(
-
1
).
abs
,
1
assert_float
Complex
(
3.0
,
-
4.0
).
abs
,
5.0
assert_float
Complex
(
3.0
,
-
4.0
).
abs
,
5.0
if
1e39
.
infinite?
then
# MRB_USE_FLOAT in effect
exp
=
125
else
exp
=
1021
end
assert_true
Complex
(
3.0
*
2
**
exp
,
4.0
*
2
**
exp
).
abs
.
finite?
assert_float
Complex
(
3.0
*
2
**
exp
,
4.0
*
2
**
exp
).
abs
,
5.0
*
2
**
exp
end
end
assert
'Complex#abs2'
do
assert
'Complex#abs2'
do
...
...
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