I am working with a function in a C library that takes a number as a parameter. Currently that means I have two versions, one for double and one for int.
What versions of functions should I provide for numeric types?
It is common to see this in the standard libraries, but they are not consistent enough to use a guideline e.g. atof, atol and atoi is one set, and strtod, strtol, strtoul is a different set and abs, labs is a third. That’s three different sets, with different naming schemes all in the same header file.
Edit:
This is not for a single use, and I do not know what variants are needed.
Ideally it would support every single standard variant, so is it sufficient to write three in the style of the strto* functions and making the user promote types where needs be?
Do you have a need for more function variants?
I suspect that given this question needs to be asked, you only have a requirement for a
doubleand anint, your two functions. If you have a genuine need to support adouble complexfor instance, build a specialized function to handle that.