Salut les C,
Comme le titre l'indique je bosse sur un projet de calculette avec entres autres fonctions de conversion et de calcul dans les 4 bases suivantes:

-Décimale.
-Binaire.
-Octal.
-Hexadécimale.

Bon après avoir construit les fonctions de conversion et de calcul j'ai attaquer une GUI avec ncurses, après une série d 'assertions:

-) 10000 random values pour les entiers dans toutes les bases: résultat de type long long ou le string binaire, octal, hexadécimale correspondant.
-) 10000 random values pour les floats dans toutes les bases: résultats de type long double ou le string binaire, octal, hexadécimale correspondant.

Passer plusieurs fois a la moulinette... c'est du tout cuit pour la GUI.

Mais ânes ignârd que je suis j'ai oublier un petit détails:
Les valeurs négatives !!!

Je me serai bien passer de votre aide, excusez la forme, mais je bute sur le fait que:

Brefs après avoir essayer en négatif,
ça passe en résultat de type (double) négatif pour la base binaire mais pas pour les autres bases (décimale omise).
Et comme les fonctions de conversions sont très analogue je ne comprend pas pourquoi le binaire ça passe et pas les autres... I Hit a -Wall.

Après mon séjours a l'hôpital pour commotion cérébrale je poste un process SOS:

Voici le code de mes assertions pour vous mettre l'eau a la bouche mais si vous voulez m'aider il faudra télécharger les sources (y pas tant de sources que ça et c'est tout commenter).

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
 
/*
 * hobdcalc 
 * Copyright (C) 2014 Bruggemann Eddie.
 * 
 * This file is part of hobdcalc  .
 * hobdcalc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * hobdcalc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with hobdcalc. If not, see <http://www.gnu.org/licenses/>
 * 
 ************************************************************************************/
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <tgmath.h>
#include <ctype.h>
#include <limits.h>
#include <inttypes.h>
#include <stdbool.h>
#include <ctype.h>
#include <errno.h>
#include <sys/time.h>
 
#include "conversion/utils/conversion_utils.c"
 
#include "conversion/int_hex/calc_int_hex.c"
#include "conversion/int_bin/calc_int_bin.c"
#include "conversion/int_oct/calc_int_oct.c" 
 
 
#include "conversion/float_to_bin/float_bin.c"
#include "conversion/float_to_oct/float_oct.c"
#include "conversion/float_to_hex/float_hex.c"
 
#include "operations/int_result/calc_hex_int_operations.c"
#include "operations/int_result/calc_oct_int_operations.c"
#include "operations/int_result/calc_bin_int_operations.c"
 
#include "operations/float_result/calc_hex_float_operations.c"
#include "operations/float_result/calc_oct_float_operations.c"
#include "operations/float_result/calc_bin_float_operations.c"
 
 
/* hobdcalc can compute in the 
 * -) binar
 * -) octal
 * -) hexadecimal
 * bases without problems with unsigned values.
 * 
 * but i hit a wall because:
 * the binar computing work with signed values for floating operations 
 * and not in octal and hexadecimal bases, and the signed integer computing.
 * because the computing functions are very similary that is why i don't understand what go wrong !!!  
 * I it the -Wall -Wall -Wall !!!
 * 
 * I hope you will have no problems with the code who is in my very simplistic beginner style. 
 *
 * You must link the type generic math file with:
 * $ gcc hobdcalc.c -lm
 * to compil the code.
 * 
 * Thank's to everybody who try to help me, 
 * if the "C HEADS break this ugly -Wall i it in"
 * thank's to send the result of their work to:
 * mrcyberfighter@gmail.com
 * or forking this code what is authorize by his author throught the GPLv3 License. 
 * 
 * For information:
 * This programm has an ncurses user interface not provided here in case as long this big bug
 * will not be resolved. 
 * 
 * Note: I don't care about strtold() or strtoll() and the %x %o %a placeholders, only raw computing, because i made
 *       bad experience with it during developpment and testing.    
 * ******************************************************************************************************************/
 
void float_operations_test(void) ;
 
void integer_operations_test(void) ;
 
int main() {
  /** float_operations_test() ; */
  /** integer_operations_test() ; */
  return 0 ;
 
}
 
void float_operations_test(void) {
  long double op1,op2 ;
  struct timeval tv ;
  char *op1_str=malloc(128) ;
  char *op2_str=malloc(128) ;
  int c ;
 
  for (c=0 ; c < 10000 ; c++) {
 
    gettimeofday(&tv,NULL) ;
    srand(tv.tv_usec / 4) ;
 
    op1=(double) (rand() % (9223372036854775807/2)) / ((rand() % (9223372036854775807/2))+1) ;
    /* set: 
     * op1 = - (double) (rand() % (9223372036854775807/2)) / ((rand() % (9223372036854775807/2))+1) ; // (long double) not work !!!
     * for help bugfix tests.
     * Thank's for your collaboration and your help.
     ******************************************/
 
    srand(tv.tv_usec / 3) ;
    op2=(double) (rand() % (9223372036854775807/2)) / ((rand() % (9223372036854775807/2))+1) ;
    /* set: 
     * op2 = - (double) (rand() % (9223372036854775807/2)) / ((rand() % (9223372036854775807/2))+1) ; // (long double) not work !!!
     * for help bugfix tests.
     * Thank's for your collaboration and your help.
     ******************************************/
 
    memset(op1_str,'\0',128) ;
    memset(op2_str,'\0',128) ;
    floattobinfloat(op1,op1_str) ;
    floattobinfloat(op2,op2_str) ;
    if (c % 10 == 0) {
      printf("iteration: %d\n",c) ;
    }
    if (op1 + op2 != binfloataddbinfloat(op1_str,op2_str) ) {
      printf("assertion bin error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,binfloataddbinfloat(op1_str,op2_str)) ;
      break ;
    }
    if (op1 - op2 != binfloatsubbinfloat(op1_str,op2_str) ) {
      printf("assertion bin error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,binfloatsubbinfloat(op1_str,op2_str)) ;
      break ;
    }
    if (op1 * op2 != binfloatmultbinfloat(op1_str,op2_str) ) {
      printf("assertion bin error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,binfloatmultbinfloat(op1_str,op2_str)) ;
      break ;
    }
    if ( (long double) op1 / (long double) op2 != binfloatdivbinfloat(op1_str,op2_str) ) {
      printf("assertion bin error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,binfloatdivbinfloat(op1_str,op2_str)) ;
      break ;
    }
    else {
      printf("%Lf\n%Lf\n%Lf\n%Lf\n",binfloataddbinfloat(op1_str,op2_str),binfloatsubbinfloat(op1_str,op2_str),binfloatmultbinfloat(op1_str,op2_str),binfloatdivbinfloat(op1_str,op2_str)) ;
    }
 
    memset(op1_str,'\0',128) ;
    memset(op2_str,'\0',128) ;
    floattohexfloat(op1,op1_str) ;
    floattohexfloat(op2,op2_str) ;
    op1_str[128]='\0' ;
    op2_str[128]='\0' ;
    if (op1 + op2 != hexfloataddhexfloat(op1_str,op2_str) ) {
      printf("assertion hex error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,hexfloataddhexfloat(op1_str,op2_str)) ;
      break ;
    }
    if (op1 - op2 != hexfloatsubhexfloat(op1_str,op2_str) ) {
      printf("assertion hex error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,hexfloatsubhexfloat(op1_str,op2_str)) ;
      break ;
    }
    if (op1 * op2 != hexfloatmulthexfloat(op1_str,op2_str) ) {
      printf("assertion hex error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,hexfloatmulthexfloat(op1_str,op2_str)) ;
      break ;
    }
    if ( (long double) op1 / (long double) op2 != hexfloatdivhexfloat(op1_str,op2_str) ) {
      printf("assertion hex error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,hexfloatdivhexfloat(op1_str,op2_str)) ;
      break ;
    }
    else {
      printf("%Lf\n%Lf\n%Lf\n%Lf\n",hexfloataddhexfloat(op1_str,op2_str),hexfloatsubhexfloat(op1_str,op2_str),hexfloatmulthexfloat(op1_str,op2_str),hexfloatdivhexfloat(op1_str,op2_str)) ;
    }
 
    memset(op1_str,'\0',128) ;
    memset(op2_str,'\0',128) ;
    floattooctfloat(op1,op1_str) ;
    floattooctfloat(op2,op2_str) ;
    if (op1 + op2 != octfloataddoctfloat(op1_str,op2_str) ) {
      printf("add assertion octal error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,octfloataddoctfloat(op1_str,op2_str)) ;
      break ;
    }
    if (op1 - op2 != octfloatsuboctfloat(op1_str,op2_str) ) {
      printf("sub assertion octal error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,octfloatsuboctfloat(op1_str,op2_str)) ;
      break ;
    }
    if (op1 * op2 != octfloatmultoctfloat(op1_str,op2_str) ) {
      printf("mult assertion oct error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,octfloatmultoctfloat(op1_str,op2_str)) ;
      break ;
    }
    if ( (long double) op1 / (long double) op2 != octfloatdivoctfloat(op1_str,op2_str) ) {
      printf("div assertion oct error by iteration %Lf:\nop1: %s == %Lf\nop2: %s == %Lf\nresult: %Lf\nerror: %Lf\n",op1,op1_str,op1,op2_str,op2,op1+op2,octfloatdivoctfloat(op1_str,op2_str)) ;
      break ;
    }
    else {
      printf("%Lf\n%Lf\n%Lf\n%Lf\n",octfloataddoctfloat(op1_str,op2_str),octfloatsuboctfloat(op1_str,op2_str),octfloatmultoctfloat(op1_str,op2_str),octfloatdivoctfloat(op1_str,op2_str)) ;
    }
 
 
  }
  free(op1_str) ;
  free(op2_str) ;
 
  return  ;
}
 
void integer_operations_test(void) {
  int c ;
  long long op1,op2 ;
  char *op1_str, *op2_str ;
  op1_str=malloc(128) ;
 
  op2_str=malloc(128) ;
 
  struct timeval tv ;
 
  for (c=0 ; c < 10000 ; c++) {
    srand(tv.tv_usec /2 ) ;
 
    op1=rand() % LLONG_MAX ;
    /* set: 
     * op1 = - rand() % LLONG_MAX ; 
     * for help bugfix tests.
     * Thank's for your collaboration and your help.
     ******************************************/
 
    srand(tv.tv_usec / 5 ) ;
 
    op2=rand() % LLONG_MAX ;
    /* set: 
     * op2 = - rand() % LLONG_MAX ; 
     * for help bugfix tests.
     * Thank's for your collaboration and your help.
     ******************************************/
 
 
    memset(op1_str,'\0',128) ;
    memset(op2_str,'\0',128) ;
    inttobin(op1,op1_str) ;
    inttobin(op2,op2_str) ;
 
    if (! (op1 + op2 == binaddbin(op1_str,op2_str) ) ) {
      printf("bin add error\n") ;
      break ;
    }
    if (! (op1 - op2 == binsubbin(op1_str,op2_str)) ) {
      printf("bin sub error\n") ;
      break ;
    }
    if (! (op1 * op2 == binmultbin(op1_str,op2_str)) ) { 
      printf("bin mult error\n") ;
      break ;
    }
    if (! ((long double) op1 / (long double) op2 == bindivbin(op1_str,op2_str)) ) {
      printf("bin div error\n") ;
      break ;
    }
    printf("-------------------------------------------------------------\n") ;
 
 
    memset(op1_str,'\0',128) ;
    memset(op2_str,'\0',128) ;
    inttooct(op1,op1_str) ;
    inttooct(op2,op2_str) ;
    if (! (op1 + op2 == octaddoct(op1_str,op2_str) ) ) {
	printf("oct add error\n") ;
	break ;
      }
    if (! (op1 - op2 == octsuboct(op1_str,op2_str)) ) {
      printf("oct sub error\n") ;
      break ;
    }
    if (! (op1 * op2 == octmultoct(op1_str,op2_str)) ) { 
      printf("oct mult error\n") ;
      break ;
    }
    if (! ((long double) op1 / (long double) op2 == octdivoct(op1_str,op2_str)) ) {
      printf("oct div error\n") ;
      break ;
    }
 
    printf("-------------------------------------------------------------\n") ;
 
    memset(op1_str,'\0',128) ;
    memset(op2_str,'\0',128) ; 
    inttohex(op1,op1_str) ;
    inttohex(op2,op2_str) ;
    if (! (op1 + op2 == hexaddhex(op1_str,op2_str) ) ) {
	printf("hex add error\n") ;
	break ;
    }
    if (! (op1 - op2 == hexsubhex(op1_str,op2_str)) ) {
      printf("hex sub error\n") ;
      break ;
    }
    if (! (op1 * op2 == hexmulthex(op1_str,op2_str)) ) { 
      printf("hex mult error\n") ;
      break ;
    }
    if (! ((long double) op1 / (long double) op2 == hexdivhex(op1_str,op2_str)) ) {
      printf("hex div error\n") ;
      break ;
    }
 
    printf("-------------------------------------------------------------\n") ;
  }
  free(op1_str) ;
  free(op2_str) ;
  return ;
 
}
Vous pouvez certes me laisser a mon triste sort mais ça serai un homicide par négligence car la tête ne résiste pas longtemps propulser a de maintes reprises contre un mur.
Je comprendrai.

Il faut savoir que les fonctions sont très basiques ainsi que mon style et je pense que vous n'aurez pas de mal a me dire ou est le problème si je suis encore vivant d'ici la.