Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Archive) Swift Range support floating point numbers?

It seems that Swift allows, in Xcode Beta, floating point number in the range operator however the results are not desirable.

for i in 0..109.88 {
     i
    sin(Double(i))
}

This causes it to hang or run for a very long time. Perhaps this is just an oversight in this release and it should only allow integers? Does it even make sense for it to allow floats?

(UPDATE: this is the very old behavior of Swift 1.0 Beta probably could be archived).

like image 948
possen Avatar asked Oct 23 '25 15:10

possen


2 Answers

This looks guaranteed to hang. Running this:

for i in 0..1.5 {
    println(i)
}

Shows that i is incremented by 1.0 each iteration to infinity. It might be waiting for i == {upper limit} to break the loop, which never happens.

like image 187
Joseph Mark Avatar answered Oct 25 '25 04:10

Joseph Mark


In the released version, this is resolved.

Joseph A Mark's answer indicated that a real number is used to increment the values. on testing the range 1.1...5.1, Swift indicated that the real range didn't have an automatic generator, so it couldn't be done.

like image 39
Owen Godfrey Avatar answered Oct 25 '25 04:10

Owen Godfrey