Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Reals in tango.math.Math

Moderators: kris

Posted: 09/19/07 17:30:19

Hello.

I've got a question: why tango's math module uses reals (such behaviour enforces programmers to use reals instead of floats/doubles)? Is this related to FPU doing maths in reals (AFAIK)? I think that in some cases, storing floats instead of reals can save tremendous amounts of memory. Besides, current GPUs operate on floats, so why ignore them?

Thanks in advance.

Author Message

Posted: 09/19/07 17:40:46

in a word: accuracy.

The D programming language will, in many cases, automatically convert for you. You're right about storage requirements in specific cases.

Posted: 09/19/07 17:54:40

Would templates for the functions be out of the question here? Seems like a good place for it... Otherwise, calls to the functions first are going to convert doubles/etc to reals, then you need to cast them back, so there's some extra processing.

Just an idea, not sure if it's a good one :)

-Steve

Posted: 09/19/07 18:09:17

That's a reasonable idea on the face of it, but then you'd likely lose accuracy as a result? The best person to ask is Don Clugston ... he's the author, and an astonishingly capable guy. If you don't catch him here, try the D newsgroup?

Posted: 10/04/07 15:33:34

Would templates for the functions be out of the question here? Seems like a good place for it... Otherwise, calls to the functions first are going to convert doubles/etc to reals, then you need to cast them back, so there's some extra processing.

In some places, yes, templates will be introduced. Interestingly, there's only a few places where it matters. Most of the large functions are so slow that the time taken in converting float<->real is negligible. Some cases are difficult because we cannot overload on return type. Eg, with float f = sqrt(2); it is only necessary to perform the calculation at float precision. It will be very interesting to see what happens when polysemous values are introduced.

My view is that the time to use floats and doubles is inside vector operations. Then we can get *serious* speedups by (for example) performing sqrt on four floats at once.