Thanks.
I am not comfortable with git but I can cross that bridge when I get there. I am assuming I can just edit my local math.nim file....
In the mean time I noticed the same problem for the "complex" module: it is not generic. Is there a Nimrod way to make this generic without loosing performance? Is there interest?
I am almost there, but I just noticed that Nimrod 0.9.4 seems to do all float32 arithmetic as float64. For example, the code
proc compEpsilon32 () : float32 =
var x: float32 = 1.0'f32
while (1.0'f32 + x > 1.0'f32):
x = x / 2.0'f32
result = x
returns 1.1102230246251565e-16, the identical value if I replace all float32 with float64 (including all constants). Even in C the above code can do this if FLT_EVAL_METHOD is 2, for example. But I am curious to know if nimrod automatically converts all float32 calculations to double? If so, is there a way around it, for example by doing what Jehan showed for complex arithmetic via the emit pragma?
Thanks.
There is something even more bothersome about the behavior of float32. For example the C function fminf(x,y) returns the minimum of x and y. So no bit mangling should occur. Nevertheless the following code fails at run-time:
proc fminf (x, y: float32): float32 {.importc, header: "<math.h>".}
assert ( fminf(1.2'f32, 2.3'f32) == 1.2'f32 )
Am I missing something? Thanks.
I have finished interfacing (almost) all the math routines in GCC C standard library for float, double, complex float and complex double. I am not sure where to post the files? In the meantime if somebody needs them I can just email it to them.
There are still some issues:
Not sure exactly how, but it looks like the following code to compute machine precision now works in both float32 and float64 as expected (with Nimrod version 0.9.5.)
proc compEpsilon [T] () : T =
result = 1.0
while (1.0 + result / 2.0 > 1.0):
result = result / 2.0