[Cuis-dev] Documentation for the different kinds of divisions

Andres Valloud ten at smallinteger.com
Mon May 25 19:45:02 PDT 2020


Yeah, it's bad.  For example,

	Float halfPi successor cos

is positive, and therefore (since there's no tan primitive either)

	Float halfPi successor tan

is positive.  Sample C programs produce sensible output instead.

Some experiments show that doing argument reduction towards zero 
minimizes error.  However, this is just a hack that illustrates the 
brittleness of the system: improving the argument reduction for cos 
causes the arcTan test to never finish because its iteration no longer 
converges.  This shows the poor behavior of cos is baked in already.

On the one hand, who cares about a few ulps, right?  On the other hand, 
whoever is careless with the truth in small matters cannot be trusted 
with important matters.

Short of reimplementing a math library from scratch, the best way to do 
transcendentals is with primitives that call the platform libraries 
everyone else uses.  Doing this properly should not be hard.

On 5/25/20 16:35, Andres Valloud via Cuis-dev wrote:
> Hi,
> 
>> It is also the implementation in Cuis :( . I guess we need a new 
>> primitive right? Maybe some simple math trick could give us the 
>> correct result?
> 
> OMG :facepalm:.  Yeah, that's bad.  The only correct way is to write a 
> primitive (other than implementing the C library in Smalltalk).
> 
> Not only you lose ulps that way, also some results will become zero when 
> they shouldn't.  Plus, there is the issue of argument reduction.
> 
>> Still, it is not obvious to me. How far is this from the correct result?
> 
> Without properly massaging the arguments given to trigonometric 
> transcendentals, and without knowing what is really going on, you can 
> get a mantissa consisting of 15 leading non-zero bits, followed by 38 
> zero bits.
> 
> This is why *nobody* should be using the x87 anymore, and for the sake 
> of compatibility the best way is to delegate to some base math library 
> that everybody else uses (because then you get the optimized numerical 
> algorithm that will cause your answers to match their answers, and then 
> you have sanity).  Unless of course you want to reimplement all of that 
> from scratch, and then Gilad's arguments start rising over the horizon 
> unless you have very good reasons.
> 
> Andres.


More information about the Cuis-dev mailing list