Menu

#1212 Tangent function possibly nees a zero-checl

GC 3.x
pending
nobody
5 - default
4 days ago
4 days ago
No

Hi here is the code of the tangent function
The function should check if the cosine is not equal to 0 before calculating the sin/cos division.

static void
cob_mpf_tan (mpf_t dst_val, const mpf_t src_val)
{
        mpf_t           vf1;
        mpf_t           vf2;

        mpf_init2 (vf1, COB_MPF_PREC);
        mpf_init2 (vf2, COB_MPF_PREC); 

        cob_mpf_sin (vf1, src_val);
        cob_mpf_cos (vf2, src_val);
        mpf_div (dst_val, vf1, vf2);

        mpf_clear (vf1);
        mpf_clear (vf2);
}

the tangent function should check if cos is not equal 0 before dividing

Discussion

  • Simon Sobisch

    Simon Sobisch - 4 days ago
    • labels: --> intrinsic, TAN
    • summary: Tangent function --> Tangent function possibly nees a zero-checl
    • status: open --> pending
     
  • Simon Sobisch

    Simon Sobisch - 4 days ago

    I'm not sure - that only happens in cases of calculations with exactly pi, which we don't have.
    The standard says because of this that the return value is only an approximation.

    GMP docs say that we'd get a signal (crash) if that happens - can you produce a crash here?
    If yes, we need a check if (mpz_sgn (vf2) == 0) (not sure what we should do then, according to the standard we may should set vf2 to 0.000000000000000001 in that case), but otherwise pointing this out in a comment could be useful.

     

Log in to post a comment.

MongoDB Logo MongoDB