Question: How can I validate if an object is of a certian class? I currently use 

```
get_class($obj) == 'User';

```

But it may look like `\KM\User` when I am elsewhere? I think this way maybe abit prone to developer error. Is there something like:

```
compare_class($obj1, User);
// or maybe
classof($obj) == User;

```

Answer: 
Taking the Square root of a general complex number can be done with the basic arithmetic operations on real numbers (plus taking square root of reals): <http://www.mathpropress.com/stan/bibliography/complexSquareRoot.pdf> (one technique is to utilise De Moivre's theorem: Any complex number a + bi can be written as `r(cos θ + i sin θ)` where

```
r = sqrt(a^2 + b^2),  cos θ = a/r, sin θ = b/r

```

**Update**: the formula `r(cos θ + i sin θ)` is originaly due to Euler, whereas De Moivre's theorem is

```
(a + ib)ⁿ = rⁿ(cos nθ + i sin nθ)

```
The square root of an integer is going to be an integer or a complex number whose real part is zero. The real part of the square root of a negative integer is zero. Always.

So ...

```
public double realPartOfSquareRoot(int i) {
    return (i > 0) Math.sqrt(i) : 0;
}

```

---

> 
> But how I solve this? If I replace the squareroot by 0, I don't get a good result. Do I suppose the imaginary part do something on the real with the rest of the formula.
> 
> 
> 

I expect that's so! (The idea of discarding the imaginary part didn't make much sense to me ... but I assumed you had a sound reason to do this.)

The real answer is to find a Java library that will do complex arithmetic. I've never needed to use it, but the first one to examine should be the [Apache Commons Maths](http://commons.apache.org/math/userguide/complex.html) library.