[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

debain, Glib et round() => comportement bizarre sous sarge gLib 2.3.2



Bonjour,

Je rentre d'une mise en service d'une nouvelle version soft sur une
ancienne plate forme debian sous sarge et je me suis rendu compte que
sur cette version j'avais des comportements inattendus lors des calculs
et de l'utilisation de la fonction round() de la bibliothèque
mathématique.

J'ai donc réalisé un petit programme de test de la fonction round
(round.c)

et je l'ai fait fonctionner sur trois cibles différentes : la cible
sarge, une cible lenny et ma station en sid.

le comportement est uniquement différent sur la version sarge où :
round(0) retourne autre chose que 0 et qu'après quelque utilisation de
round la variable n n'est plus reconnue comme un double.

Je ne vois pas où pourrait être la différence ou la "mauvaise
utilisation" de round().

Je n'ai pas trouvé non plus de point d'entrée sur la glib pour round(),
mais là je ne suis pas sûr d'avoir bien cherché.

Est-ce quelqu'un a déjà rencontré ce type de problème ?

Bien entendu, la mise à jour de la cible n'est pas une option viable
pour pleins de mauvaises raisons bien terre à terre !

Merci d'avance.

En pièces jointes :
- round.c le programme simple de test
- test.sh le srcipt de test executé sur chaque cible,
- sid.txt résultat sur sid
- lenny.txt résultat sur lenny
- sarge.txt résultat sur sarge

--
Yann COHEN
uname
Linux lenny 2.6.26-2-486 #1 Tue Mar 9 17:10:34 UTC 2010 i686 GNU/Linux

glibc
GNU C Library stable release version 2.7, by Roland McGrath et al.

Compilation
round.c: In function â??mainâ??:
round.c:14: warning: incompatible implicit declaration of built-in function â??roundâ??

Sans utilisation de round()
-0.0000/2.0000=-0.0000
0.0010/2.0000=0.5000
0.0020/2.0000=1.0000
0.0030/2.0000=1.5000
0.0040/2.0000=2.0000
0.0050/2.0000=2.5000
0.0060/2.0000=3.0000
0.0070/2.0000=3.5000
0.0080/2.0000=4.0000
0.0090/2.0000=4.5000
0.0100/2.0000=5.0000
0.0110/2.0000=5.5000
0.0120/2.0000=6.0000
0.0130/2.0000=6.5000
0.0140/2.0000=7.0000
0.0150/2.0000=7.5000
0.0160/2.0000=8.0000
0.0170/2.0000=8.5000
0.0180/2.0000=9.0000
0.0190/2.0000=9.5000

Avec utilisation de round()
-0.0000/2.0000=-0.0000 round(-0.0000 0)
0.0010/2.0000=0.5000 round(1.0000 1)
0.0020/2.0000=1.0000 round(1.0000 1)
0.0030/2.0000=1.5000 round(2.0000 2)
0.0040/2.0000=2.0000 round(2.0000 2)
0.0050/2.0000=2.5000 round(3.0000 3)
0.0060/2.0000=3.0000 round(3.0000 3)
0.0070/2.0000=3.5000 round(4.0000 4)
0.0080/2.0000=4.0000 round(4.0000 4)
0.0090/2.0000=4.5000 round(5.0000 5)
0.0100/2.0000=5.0000 round(5.0000 5)
0.0110/2.0000=5.5000 round(6.0000 6)
0.0120/2.0000=6.0000 round(6.0000 6)
0.0130/2.0000=6.5000 round(7.0000 7)
0.0140/2.0000=7.0000 round(7.0000 7)
0.0150/2.0000=7.5000 round(8.0000 8)
0.0160/2.0000=8.0000 round(8.0000 8)
0.0170/2.0000=8.5000 round(9.0000 9)
0.0180/2.0000=9.0000 round(9.0000 9)
0.0190/2.0000=9.5000 round(10.0000 10)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main(int argc, char *argv[])
{
	double n, d=2, q, r;
	int nb = 20;
	
	while(nb--) {
		q = n / d * 1E3;
		printf("%.4lf/%.4lf=%.4lf", n, d, q);
		if (argc > 1) {
			r = round(q);
			printf(" round(%.4lf %ld)", r, (long)r);
		}
		printf("\n", r, (long)r);
		n += 0.001;
		//d *= 1.3;
	}
}
uname
Linux sarge 2.6.8-2-386 #1 Tue Aug 16 12:46:35 UTC 2005 i686 GNU/Linux

glibc
GNU C Library stable release version 2.3.2, by Roland McGrath et al.

Compilation

Sans utilisation de round()
0.0000/2.0000=0.0000
0.0010/2.0000=0.5000
0.0020/2.0000=1.0000
0.0030/2.0000=1.5000
0.0040/2.0000=2.0000
0.0050/2.0000=2.5000
0.0060/2.0000=3.0000
0.0070/2.0000=3.5000
0.0080/2.0000=4.0000
0.0090/2.0000=4.5000
0.0100/2.0000=5.0000
0.0110/2.0000=5.5000
0.0120/2.0000=6.0000
0.0130/2.0000=6.5000
0.0140/2.0000=7.0000
0.0150/2.0000=7.5000
0.0160/2.0000=8.0000
0.0170/2.0000=8.5000
0.0180/2.0000=9.0000
0.0190/2.0000=9.5000

Avec utilisation de round()
0.0000/2.0000=0.0000 round(32.0000 32)
0.0010/2.0000=0.5000 round(14368.0000 14368)
0.0020/2.0000=1.0000 round(0.0000 0)
0.0030/2.0000=1.5000 round(534560.0000 534560)
0.0040/2.0000=2.0000 round(0.0000 0)
0.0050/2.0000=2.5000 round(268320.0000 268320)
0.0060/2.0000=3.0000 round(0.0000 0)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
nan/2.0000=nan round(2047.0000 2047)
uname
Linux yan 2.6.32-5-amd64 #1 SMP Mon Mar 7 21:35:22 UTC 2011 x86_64 GNU/Linux

glibc
GNU C Library (Debian EGLIBC 2.11.2-11) stable release version 2.11.2, by Roland McGrath et al.

Compilation

Sans utilisation de round()
0.0000/2.0000=0.0000
0.0010/2.0000=0.5000
0.0020/2.0000=1.0000
0.0030/2.0000=1.5000
0.0040/2.0000=2.0000
0.0050/2.0000=2.5000
0.0060/2.0000=3.0000
0.0070/2.0000=3.5000
0.0080/2.0000=4.0000
0.0090/2.0000=4.5000
0.0100/2.0000=5.0000
0.0110/2.0000=5.5000
0.0120/2.0000=6.0000
0.0130/2.0000=6.5000
0.0140/2.0000=7.0000
0.0150/2.0000=7.5000
0.0160/2.0000=8.0000
0.0170/2.0000=8.5000
0.0180/2.0000=9.0000
0.0190/2.0000=9.5000

Avec utilisation de round()
0.0000/2.0000=0.0000 round(0.0000 0)
0.0010/2.0000=0.5000 round(1.0000 1)
0.0020/2.0000=1.0000 round(1.0000 1)
0.0030/2.0000=1.5000 round(2.0000 2)
0.0040/2.0000=2.0000 round(2.0000 2)
0.0050/2.0000=2.5000 round(3.0000 3)
0.0060/2.0000=3.0000 round(3.0000 3)
0.0070/2.0000=3.5000 round(4.0000 4)
0.0080/2.0000=4.0000 round(4.0000 4)
0.0090/2.0000=4.5000 round(5.0000 5)
0.0100/2.0000=5.0000 round(5.0000 5)
0.0110/2.0000=5.5000 round(6.0000 6)
0.0120/2.0000=6.0000 round(6.0000 6)
0.0130/2.0000=6.5000 round(7.0000 7)
0.0140/2.0000=7.0000 round(7.0000 7)
0.0150/2.0000=7.5000 round(8.0000 8)
0.0160/2.0000=8.0000 round(8.0000 8)
0.0170/2.0000=8.5000 round(9.0000 9)
0.0180/2.0000=9.0000 round(9.0000 9)
0.0190/2.0000=9.5000 round(10.0000 10)

Attachment: test.sh
Description: application/shellscript


Reply to: