# How do I multiply an integer and a double in Q#?

If I write this:

function f(n: Int) : Double {
return 1.5*n;
}


I get an error:

The arguments to the binary operator do not have a common base type.


Apparently I need a function to turn n from an Int into a Double. There are lots of functions going from double to int, like Microsoft.Quantum.Extensions.Math.Floor, but I wasn't able to find anything from int to double.

• You mean you want to know how subtyping is indicated in this language. Because (Num a) => a -> a -> a is not the same as (Num a,Num b) => a -> b -> a as Haskell would denote it. – AHusain Dec 30 '18 at 4:16
• @AHusain No, I was really just looking for the ToDouble function and couldn't find it. I know it's a dumb question, but that's the point of stack exchange: make task-oriented and problem-oriented documentation that's faster than searching the manual. – Craig Gidney Dec 30 '18 at 4:34
• This sort of question would be all good from someone who was new and didn't have the terminology to search. But it just doesn't seem to make sense to me coming from someone who already knows what to search for and how. – AHusain Dec 30 '18 at 5:09
• @AHusain I actually didn't know what to search for, or how. The documentation on types didn't say anything about it, autocomplete wasn't working, google doesn't understand that Q# is a term, and I didn't realize there was supposed to be a function list on the docs site (I use noscript and it just doesn't show unless you allow scripts). – Craig Gidney Dec 30 '18 at 8:54
• @CraigGidney: One thing we've found useful in searching for Q# on Google is to use "qsharp" as a search term rather than Q#. The query "qsharp" convert int to double returns ToDouble as the second hit for me in a private tab. – Chris Granade Dec 31 '18 at 5:21

You want the Microsoft.Quantum.Extensions.Convert.ToDouble function (deprecated in favor of Microsoft.Quantum.Convert.IntAsDouble in 0.6 release).
open Microsoft.Quantum.Extensions.Convert;

The reason it works this way is because in Q# (Num a) => a -> a -> a is not the same as (Num a,Num b) => a -> b -> a as Haskell would denote it.