LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Andrew Parsloe <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Fri, 14 Apr 2017 20:14:45 +1200
text/plain (57 lines)
On 14/04/2017 2:28 p.m., Bruno Le Floch wrote:
> On 04/02/2017 12:09 AM, Andrew Parsloe wrote:
>> Is there a simple way to distinguish -0 from 0 in l3fp?
>> I had been aligning left in a table a column of sines, +0 or -0 followed
>> by decimal point & digits. By adding an \hphantom{-} before the positive
>> numbers, they aligned nicely on the decimal point in the column, but
>> then along came -0. The simple conditional, "if !(number < 0) add
>> phantom", added the phantom and the column aligned like
>>   0
>>   0.5878
>>   -0
>> -0.5878
>> etc.
>> In the absence of formatted printing of numbers, -0 is a problem. Even a
>> built-in test for -0 would ease matters, since in any kind of formatted
>> printing of numbers 0 and -0 will generally require different handling.
>> As it is, I've had to test each fp for whether it is zero; if it is I
>> convert to a tl variable and test whether that is -0. This is clumsy.
>> Hence my opening question.
>> Andrew
> Sorry for the delay.
> One option is to normalize -0 to +0 by adding +0.  Namely, number+0 is
> equal to number for any non-zero number and is +0 for both +0 and -0.
> Another option is to compute 1/number after disabling the
> "division-by-zero" trap, and test whether that's +inf or -inf, but
> that's more complicated than the tl test you're doing.
> A better option is that I should add a "copysign" function, that is in
> the IEEE standard: copysign(1,x) gives +1 or -1 depending on the sign
> bit of x (so in particular this distinguishes +0 and -0).
> For your specific use case I would use \fp_to_tl:n then test whether the
> first character (\str_head:n) is "-" or not.  This also covers nan properly.
> Bruno
Ah, the "add +0" suggestion is helpful, and certainly simpler than what 
I was doing.

You implemented, very promptly, an earlier suggestion of mine about 
adding "sign" to l3fp. Thank you. In the course of dealing with the 
above problem I noticed that sign(-0) = -0. I presume this is the 
expected result. (I was rather hoping sign(x) might evaluate to one of 
the *three* values -1, 0, 1.)


This email has been checked for viruses by Avast antivirus software.