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.