Efficient rounding of multiplication by irrational numbers

I have a small Julia package for quantum computing - performing simple qubit calculations (I know that there are other, high quality, quantum computations for Julia, but I like to use my package which is tailored for my own needs).

Since Quantum computation is basically martix multiplication it is fairly simple to perform the operations using the available linear algebra methods. However, as there are a lot of sqrt(2) used (mainly in Hadamard gates) in a quantum computation, the result of a computation which should be a “nice” number (e.g. 0.5) ends up with rounding errors (e.g. 0.499999…).

Using symbolic math would certainly solve the problem. However, this would slow down the computation time considerably.

Is there an efficient method for fixing these rounding errors, and (perhaps, even,) convert a floating point result (e.g. 1.0) to an integer when appropriate?

1 Like