Provide two parallel sets of functions: one for implementation using float , and another for implementation using double (and the third for long double ). This is what the C library does - there is sin() for double , sinf() for float and sinl() for long double .
Or, in C ++, you could (perhaps should?) Consider using overloads or templates. My suspicion, however, is that this can lead to confusion rather than simplicity (or, basically, it will use double overloads, since double floating point literals are not explicitly specified) but templates are often the method of choice these days .
(Comments modified in the light of bstamour's comments, I was too conservative and was in the 1990s.)
source share