eharo2
eharo2

Reputation: 2642

Why does Swift report CGFloat.pi.significand to be exactly pi/2?

Running Xcode 11.3

Why is the significant component of pi equal to pi/2?

print(CGFloat.pi.significand == CGFloat.pi/2).   // true

I expected the significant to be equivalent to the mantissa.. Did I miss something?

Upvotes: 2

Views: 141

Answers (1)

udi
udi

Reputation: 3853

We declare significand as follows.

let magnitude = x.significand * F.radix ** x.exponent

I assume pi = 3.14.

So pi = 1.57 * 2 1 where 1.57 is the significand.

If we divide both sides by 2 you will get pi/2 = 1.57.

In other words pi/2 = pi.significand. (this is kind of a special case).

According to the apple documentation,

The significand is frequently also called the mantissa, but significand is the preferred terminology in the IEEE 754 specification, to allay confusion with the use of mantissa for the fractional part of a logarithm.

Update

As mentioned by @Ptit all numbers between 2 and 4 satisfies the argument number/2 = number.significand.

Upvotes: 5

Related Questions