4 ms·
How does adding Array(1.0, 2.0, 3.0, 4.0) and Array(4.0, 3.0, 2.0, 1.0) result in Array(1.7302967433402214, 2.547722557505166, 3.36514837167011
by sampo 10y ago
How does adding
Array(1.0, 2.0, 3.0, 4.0)
and
Array(4.0, 3.0, 2.0, 1.0)
result in
Array(1.7302967433402214, 2.547722557505166, 3.3651483716701107, 4.182574185835056)
- QuercusMax 10y agoThat does seem very strange.
- jordigh 10y agoFloats are weird and unpredictable like that. You can save yourself an RNG call if you simply add two floats. ;-) More seriously, the result here really is x + y/norm(y). I would be really interested in knowing what the bug is here. Probably just a C&P error that forgot to update the result, since y is unitized (in-place?) in a call further below.
- haifeng 10y agoIs there something wrong in your code? I don't see the effect. smile> val x = Array(1.0, 2.0, 3.0, 4.0) x: Array[Double] = Array(1.0, 2.0, 3.0, 4.0) smile> val y = Array(4.0, 3.0, 2.0, 1.0) y: Array[Double] = Array(4.0, 3.0, 2.0, 1.0) smile> x + y res2: smile.math.VectorAddVector = Array(5.0, 5.0, 5.0, 5.0)
- sampo 10y agoOk, they have fixed the website now.