Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Floating point error in turbo c++

2»

Comments

  • inspokeninspoken Member Posts: 9
    you need to protect t=pow(2,t) before calling it. You also might want to cast t into a double not an int for instance
    double tmp=(double)t;
    if(fabs(tmp)>1000.0)
    return some_error_code;
    tmp=pow(2.0,tmp);
    if(fabs(tmp)<32000.0)
    t=(int)tmp;
    else
    return some_other_type_of_error
  • inspokeninspoken Member Posts: 9
    you need to protect t=pow(2,t) before calling it. You also might want to cast t into a double not an int for instance
    double tmp=(double)t;
    if(fabs(tmp)>1000.0)
    return some_error_code;
    tmp=pow(2.0,tmp);
    if(fabs(tmp)<32000.0)
    t=(int)tmp;
    else
    return some_other_type_of_error
  • inspokeninspoken Member Posts: 9
    you need to protect t=pow(2,t) before calling it. You also might want to cast t into a double not an int for instance
    double tmp=(double)t;
    if(fabs(tmp)>1000.0)
    return some_error_code;
    tmp=pow(2.0,tmp);
    if(fabs(tmp)<32000.0)
    t=(int)tmp;
    else
    return some_other_type_of_error
  • inspokeninspoken Member Posts: 9
    you need to protect t=pow(2,t) before calling it. You also might want to cast t into a double not an int for instance
    double tmp=(double)t;
    if(fabs(tmp)>1000.0)
    return some_error_code;
    tmp=pow(2.0,tmp);
    if(fabs(tmp)<32000.0)
    t=(int)tmp;
    else
    return some_other_type_of_error
  • inspokeninspoken Member Posts: 9
    you need to protect t=pow(2,t) before calling it. You also might want to cast t into a double not an int for instance
    double tmp=(double)t;
    if(fabs(tmp)>1000.0)
    return some_error_code;
    tmp=pow(2.0,tmp);
    if(fabs(tmp)<32000.0)
    t=(int)tmp;
    else
    return some_other_type_of_error
2»
Sign In or Register to comment.