LoginSignup
0
0

More than 1 year has passed since last update.

Swiftの16進数小数の指数のポイント

Last updated at Posted at 2017-07-29

Swiftの16進数小数で、勘違いしていた部分があったのでまとめを書きました。

Swiftの16進数小数は必ず指数部分を付けないといけない

let a = 0x1.0p0 //OK
let b = 0x1.0 //NG
let c = 0x1 //OK 整数は指数が必要ではない

指数表記はpで始める

let a = 0x1.0p0 //OK
let b = 0x1.0e0 //NG
let c = 1.0e0 //OK 10進の場合はe

指数表記は10進数で表記する

let a = 0x1.0p10 //OK
let b = 0x1.0pa //NG

小数点移動は2進数状態で行われる(ここが盲点)

let a = 0x1.0p1
let b = 0x10.0p0 //10進数で16
let c = 0x2.0p0 //10進数で2
a == b //false
a == c //true

小数点移動は2進数状態で行われることが盲点でした。

0
0
0

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
0