Search
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby
All Projects
Ruby
Overview
Activity
Roadmap
Issues
Repository
Download (514 Bytes)
Bug #4308
ยป wrong_bignum_calc.rb
shouichi (Shouichi Kamiya)
, 01/24/2011 06:59 AM
#!/usr/bin/env ruby
class
Array
def
sum
reduce
(
0
)
{
|
s
,
i
|
s
+=
i
}
end
def
avg
empty?
?
0.0
:
sum
.
to_f
/
size
end
def
var
empty?
?
0.0
:
map
{
|
x
|
x
**
2
}.
avg
-
avg
**
2
end
end
# All of these should clearly return 0.
p
[
1295218865
,
1295218865
,
1295218865
,
1295218865
,
1295218865
].
var
#=> 0.0
p
[
1295218865
,
1295218865
,
1295218865
,
1295218865
,
1295218865
,
1295218865
].
var
#=> 256.0
p
[
1295218865
,
1295218865
,
1295218865
,
1295218865
,
1295218865
,
1295218865
,
1295218865
].
var
#=> 0.0
(1-1/1)
Loading...