The problem I see is that metaP effectively abuses enumerations in variables. The problem is that enumerations are processed internally as integers, which exclude an attempt to get a floating point value from them. However, you can create your own floating point format that creates two results, the integer part and the exponent. You still have to handle this in a float, like Out = Sqrt<42>::mantissa * pow(10,Sqrt<42>::exponent); . In fact, defining the values remains as an exercise for the reader, but you will probably have to scale the input up (using uniform power of 10) by calculating the root and keeping the -power / 2 you used earlier.
To calculate sqrt <42>, you must first set the enumeration of exhibitors to a suitable capacity, for example, "-4" (lower, more decimal, but watch overflow). Then you multiply the input by '10 ^ (- 2 * exponent) '. In this case, you get 42 * 10 ^ 8 = 4200000000. Then you take the root of this value, getting "64807" as the final value. At run time, you calculate the value "val * 10 ^ exponent" = "64807 * 10 ^ -4" = 64807 * 0.0001 = 6.4807m and save it in the float.
The extra conversion work causes the target to fail, but you can slightly reduce it by saving the metric as 10 ^ k (i.e. 10 ^ 4), then doing out=sqrt<x>::mantissa/sqrt<x>::exponent .
edit I just noticed that using the mantissa / exponent method, the choice of an indicator is arbitrary as long as it is larger than the integer part of the final root. It can even be permanent, which makes it easier to develop your meta functions. For example, in case 42, you can choose “exponent” always 6000. Then you multiply the input by 6000 ^ 2, take the integer root of the product, then divide the result by 6000 to get the root, Instead of processing the output as a * 10 ^ b it uses the relation sqr (x * b ^ 2) = sqr (x) * b. Mathematics is checked:
- 42 * 6000 * 6000 = 1512000000
- SQR (1512000000) = 38884
- 38884/6000 = 6.4806 (square - 41.999)
source share