Re: [q-lang-users] Floating point arithmetics
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2008-01-05 11:07:47
|
Jir(í Spitz wrote: > Therefore I would like to ask how Q does represent floating point > numbers and whether there is some workaround of that. They are double precision (64 bit), whatever the C compiler provides (that's usually IEEE 754 these days). AFAICT, this is exactly what Erlang uses by default, so if your code runs interpreted (using bytecodes) then the results should be the same (rounding errors during I/O notwithstanding). But if you compile your Erlang program to native code, the actual precision may be higher, e.g., 80 bit on x86 systems, since the compiler will keep floating point values on the x87 stack as long as possible [1]. This isn't offered by Q right now, as we don't have a native code compiler yet, so this may explain the differences that you see. As for workarounds, double precision is the only floating point type that Q offers right now, so you're out of luck with the builtin arithmetic. It should be possible to implement multiprecision floating point arithmetic in Q, using, e.g., the MPFR library [2], but that needs some work. If your algorithms work with rational numbers, you could use rational arithmetic which is readily available in Q [3], but this isn't a silver bullet either and I doubt that it will be practical with ill-conditioned matrices because the numerators and denominators might get very large. [1] ftp://ftp.csd.uu.se/pub/papers/masters-theses/0229-lindahl.pdf [2] http://www.mpfr.org/ [3] http://q-lang.sourceforge.net/qdoc/qdoc_11.html#SEC97 HTH, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |