What is the problem that needs to be fixed? What should the correct result be?
When is the absolute value of a number close enough to zero for the number to be considered zero? Should a number in an array be considered to be zero based on its value independent of other numbers in the array or should other values in the array be considered? How small should the imaginary or real part be to be considered zero when the absolute value is comparably large? To answer these questions we need a clear definition of the the problem to be solved. There are no general answers. The answers will depend on the application. All solutions presented so far probably will result in precision loss. So they are probably not useful for additional computation, depending on the application. So I assume it is to make the output look prettier. On Wed, May 2, 2012 at 9:45 AM, Raul Miller <rauldmil...@gmail.com> wrote: > I don't think rounding is desirable, here. > > Instead, what is desired is a mechanism analogous to the display > precision where the precision of the collection is based on its > largest members. > > But all that's needed here, is a loss of a few unnecessary bits of > precision. So what we do is add a number (which drops a few bits of > precision) and then subtract it again. > > FYI, > > -- > Raul > > > On Wed, May 2, 2012 at 11:31 AM, Edward Mokurai Cherlin > <moku...@sugarlabs.org> wrote: > > On Wed, May 2, 2012 6:11 am, Bo Jacoby wrote: > >> Hello J'ers > >> > >> Even if a complex number is actually real it may display nonzero > imaginary > >> part because of round-off errors. Adding and subtracting 1e6j1e6 removes > >> the round-off error, but is there a better or more general solution? > > > > J uses the APL definition of complex floor, so normal rounding works. > > > > <.1j0.00000001+0.5 > > 1 > > _1+<.1j0.00000001+0.5 > > 0 > > > > -- > > Edward Mokurai (默雷/निशब्दगर्ज/نشبدگرج) Cherlin > > Silent Thunder is my name, and Children are my nation. > > The Cosmos is my dwelling place, the Truth my destination. > > http://wiki.sugarlabs.org/go/Replacing_Textbooks > > > > > > -- > > Edward Mokurai (默雷/निशब्दगर्ज/نشبدگرج) Cherlin > > Silent Thunder is my name, and Children are my nation. > > The Cosmos is my dwelling place, the Truth my destination. > > http://wiki.sugarlabs.org/go/Replacing_Textbooks > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm