Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
Can the standard math functions handle infinity correctly?
int main() {
    double inf = INFINITY;
    double pi = acos(-1.0);
    printf("[1]: %f %f\n", atan(inf) / pi, atan(-inf) / pi);
    printf("[2]: %f %f\n", tan(inf) / pi, tan(-inf) / pi);
    return 0;
}

outputs

[1]: 0.500000 -0.500000
[2]: -nan -nan

Is such behaviour defined by the standard? Is [2] undefined behaviour? unspecified?

I want to be sure at least [1] is a guaranteed result.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Both are well defined behaviour. Quoting from http://en.cppreference.com

  • tan

    If the argument is ±0, it is returned unmodified.
    If the argument is ±∞, NaN is returned and FE_INVALID is raised.
    If the argument is NaN, NaN is returned.

  • atan

    If the argument is ±0, it is returned unmodified.
    If the argument is +∞, +π/2 is returned.
    If the argument is -∞, -π/2 is returned.
    If the argument is NaN, NaN is returned.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda