LoginSignup
0
2

More than 5 years have passed since last update.

正の数なら1,負の数なら-1,ゼロなら0を返す式

Last updated at Posted at 2018-12-25
// aはある数
let result1 = a > 0 ? 1 : (a < 0 ? -1 : 0)

let result2 = a == 0 ? 0 : Int(a / abs(a))

これらよりいい式ありますでしょうか?

0
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2