In creating trig functions my_sind(d)
, my_cosd(d)
, my_tand(d)
, that used a degree argument rather than a radian one and provided exact answers at multiples of 90, I noticed that the result was sometimes -0.0
rather than 0.0
.
my_sind( 0.0) --> 0.0
my_sind(-0.0) --> -0.0
my_sind(180.0) --> -0.0
my_sind(360.0) --> 0.0
sin()
and tan()
typically return the same sign zero result for a given sign zero input. It makes sense that my_sin()
should match sin()
for those inputs.
my_sind( 0.0) alike sin( 0.0) --> 0.0
my_sind(-0.0) alike sin(-0.0) --> -0.0
The question is: for what whole number non_zero_n
should/may the result ever return -0.0
for my_sind(180*non_zero_n)
, my_cosd(180*n + 180)
, my_tand(180*non_zero_n)
?
It is easy enough to code so only f(-0.0)
produces -0.0
and be done with it. Simple wondering if there is any reason to make other f(x)
return -0.0
for any other (non-zero) x
and the importance of insuring that sign.
Note: This is not a question of why 0.0
vs. -0.0
occurs. This is not why cos(machine_pi/4)
does not return 0.0
. Neither is this a question of how to control the generation of 0.0
or -0.0
. I see it best as a design question.
sind(180), sind(-180), sind(360), sind(-360),...
? – chux - Reinstate Monica Nov 03 '14 at 12:33my_trig(x)
ever return-0.0
when|x|
is not0.0
? – chux - Reinstate Monica Nov 03 '14 at 15:33+0.0
, but looking to see if there are compelling reasons to return-0.0
in some situations (other thanx == +/-0.0
). – chux - Reinstate Monica Nov 03 '14 at 18:22180.0
, one really has to examine the values of relative machine precision given those values. That is, the smallest increment/decrement that gives a different representable value in that numerical format. Then, compare that value with the true value to see whether it would fall on the plus side or minus side. – rwong Jan 03 '15 at 22:23sind(double degrees)
andcosd(double degrees)
value can be returned:-1.0, +0.0, +1.0
. This post is about should-0.0
ever be returned (aside from sind(-0.0)). Note:sind()
does not use the simplisticsin(x/360*M_PI)
approach. – chux - Reinstate Monica Jan 04 '15 at 01:50