Idée de concours : Optimisation de code

A mon avis si on veux faire un concours, il faut être précis dans la spécification fonctionnelle. Savoir écrire ou savoir lire un cahier des charges c'est la base des compétences nécessaires pour un bon développeur.

Par exemple un nombre flottant peut être représenté en notation scientifique: 123.345e-12 ou un entier peut être gigantesque 123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789. Que doit faire le code ?

Bien sûr ce genre de question s'est déjà posée il y a bien longtemps et l'approche standard en C ou C++ serait d'utiliser errno pour reporter une erreur ERANGE et de retourner le plus petit ou plus grand nombre représentable

de même l'approche standard pour la représentation d'un nombre serait de se rapprocher de ce que fait stdlib.h par exemple pour strtod() ou strtol()

leur définition de la lecture d'un nombre entier dans une certaine base est

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax that depends on the base parameter, and interprets them as a numerical value. Finally, a pointer to the first character following the integer representation in str is stored in the object pointed by endptr.

If the value of base is zero, the syntax expected is similar to that of integer constants, which is formed by a succession of:
An optional sign character (+ or -)
An optional prefix indicating octal or hexadecimal base ("0" or "0x"/"0X" respectively)
A sequence of decimal digits (if no base prefix was specified) or either octal or hexadecimal digits if a specific prefix is present

If the base value is between 2 and 36, the format expected for the integral number is a succession of any of the valid digits and/or letters needed to represent integers of the specified radix (starting from '0' and up to 'z'/'Z' for radix 36). The sequence may optionally be preceded by a sign (either + or -) and, if base is 16, an optional "0x" or "0X" prefix.

If the first sequence of non-whitespace characters in str is not a valid integral number as defined above, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

de même pour un nombre décimal:

A valid floating point number for strtod using the "C" locale is formed by an optional sign character (+ or -), followed by a sequence of digits, optionally containing a decimal-point character (.), optionally followed by an exponent part (an e or E character followed by an optional sign and a sequence of digits).