[#48591] StringValuePtrでnull終止されてない文字列の作り方 — madoka yamamoto <yamamotomadoka@...>
山本ともうします。
5 messages
2014/10/05
[#48598] Re: StringValuePtrでnull終止されてない文字列の作り方
— "NARUSE, Yui" <naruse@...>
2014/10/06
まず、CRubyとしてはStringValuePtrがNUL終端する保証はしていませんから、仮にnull-terminateしてないことにより問題が起きるならば、
[#48666] Re: [ruby-cvs:55171] duerst:r48021 (trunk): common.mk: Added a rule to generate lib/unicode_normalize/tables.rb. — "Martin J. Dürst" <duerst@...>
中田さん、こんにちは。
3 messages
2014/10/19
[ruby-dev:48621] [ruby-trunk - Feature #10298] Array#float_sum (like math.fsum of Python)
From:
akr@...
Date:
2014-10-13 06:46:12 UTC
List:
ruby-dev #48621
Issue #10298 has been updated by Akira Tanaka.
It is not fit to Array class because Array is not only for Float.
I think it is better to implement it as an optimization of reduce(:+).
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-49376
* Author: Takeshi Nishimatsu
* Status: Open
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/