Kahan summation: Difference between revisions

(→‎{{header|Ruby}}: Added Ruby)
Line 2,012:
ªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªª</pre>
 
=={{header|Ruby}}==
Arrays provide a "sum" method, which uses a Kahan-Babuska balancing compensated summation algorithm, according to the C-source.
<lang ruby>epsilon = 1.0
epsilon /= 2 until 1.0 + epsilon == 1.0
 
a = 1.0
b = epsilon
c = -b
 
puts "epsilon : #{epsilon}"
puts "(a+b)+c : #{(a+b)+c}"
puts "[a,b,c].sum: #{[a,b,c].sum}"
</lang>
{{out}}
<pre>epsilon : 1.1102230246251565e-16
(a+b)+c : 0.9999999999999999
[a,b,c].sum: 1.0
</pre>
=={{header|Scala}}==
===IEEE 754 Single precision 32-bit (JavaScript defaults to Double precision.)===
Line 2,045 ⟶ 2,063:
{{Out}}See it running in your browser by [https://scalafiddle.io/sf/lWI0SJC/0 ScalaFiddle (JavaScript, non JVM)] or by [https://scastie.scala-lang.org/CI7dNAKQSlupivKAnYcGJg Scastie (remote JVM)].
Note: JVM float is IEEE-754 32 bit floating point while JavaScript always default to the IEEE 754 standard 64-bit.
 
=={{header|Tcl}}==
===Tcl: Floats===
1,149

edits