Changes in uspace/lib/softfloat/generic/comparison.c [88d5c1e:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/generic/comparison.c
r88d5c1e r9d58539 45 45 * @return 1 if float is NaN, 0 otherwise. 46 46 */ 47 int is _float32_nan(float32 f)47 int isFloat32NaN(float32 f) 48 48 { 49 49 /* NaN : exp = 0xff and nonzero fraction */ … … 58 58 * @return 1 if float is NaN, 0 otherwise. 59 59 */ 60 int is _float64_nan(float64 d)60 int isFloat64NaN(float64 d) 61 61 { 62 62 /* NaN : exp = 0x7ff and nonzero fraction */ … … 71 71 * @return 1 if float is NaN, 0 otherwise. 72 72 */ 73 int is _float128_nan(float128 ld)73 int isFloat128NaN(float128 ld) 74 74 { 75 75 /* NaN : exp = 0x7fff and nonzero fraction */ … … 84 84 * @return 1 if float is signalling NaN, 0 otherwise. 85 85 */ 86 int is _float32_signan(float32 f)86 int isFloat32SigNaN(float32 f) 87 87 { 88 88 /* SigNaN : exp = 0xff and fraction = 0xxxxx..x (binary), … … 98 98 * @return 1 if float is signalling NaN, 0 otherwise. 99 99 */ 100 int is _float64_signan(float64 d)100 int isFloat64SigNaN(float64 d) 101 101 { 102 102 /* SigNaN : exp = 0x7ff and fraction = 0xxxxx..x (binary), … … 112 112 * @return 1 if float is signalling NaN, 0 otherwise. 113 113 */ 114 int is _float128_signan(float128 ld)114 int isFloat128SigNaN(float128 ld) 115 115 { 116 116 /* SigNaN : exp = 0x7fff and fraction = 0xxxxx..x (binary), … … 128 128 * @return 1 if float is infinite, 0 otherwise. 129 129 */ 130 int is _float32_infinity(float32 f)130 int isFloat32Infinity(float32 f) 131 131 { 132 132 /* NaN : exp = 0x7ff and zero fraction */ … … 140 140 * @return 1 if float is infinite, 0 otherwise. 141 141 */ 142 int is _float64_infinity(float64 d)142 int isFloat64Infinity(float64 d) 143 143 { 144 144 /* NaN : exp = 0x7ff and zero fraction */ … … 152 152 * @return 1 if float is infinite, 0 otherwise. 153 153 */ 154 int is _float128_infinity(float128 ld)154 int isFloat128Infinity(float128 ld) 155 155 { 156 156 /* NaN : exp = 0x7fff and zero fraction */ … … 165 165 * @return 1 if float is zero, 0 otherwise. 166 166 */ 167 int is _float32_zero(float32 f)168 { 169 return (((f.bin ) & 0x7FFFFFFF) == 0);167 int isFloat32Zero(float32 f) 168 { 169 return (((f.binary) & 0x7FFFFFFF) == 0); 170 170 } 171 171 … … 176 176 * @return 1 if float is zero, 0 otherwise. 177 177 */ 178 int is _float64_zero(float64 d)179 { 180 return (((d.bin ) & 0x7FFFFFFFFFFFFFFFll) == 0);178 int isFloat64Zero(float64 d) 179 { 180 return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0); 181 181 } 182 182 … … 187 187 * @return 1 if float is zero, 0 otherwise. 188 188 */ 189 int is _float128_zero(float128 ld)189 int isFloat128Zero(float128 ld) 190 190 { 191 191 uint64_t tmp_hi; 192 192 uint64_t tmp_lo; 193 194 and128(ld.bin .hi, ld.bin.lo,193 194 and128(ld.binary.hi, ld.binary.lo, 195 195 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 196 196 197 197 return eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll); 198 198 } … … 205 205 * @return 1 if both floats are equal, 0 otherwise. 206 206 */ 207 int is _float32_eq(float32 a, float32 b)207 int isFloat32eq(float32 a, float32 b) 208 208 { 209 209 /* a equals to b or both are zeros (with any sign) */ 210 return ((a.bin == b.bin) ||211 (((a.bin | b.bin) & 0x7FFFFFFF) == 0));210 return ((a.binary == b.binary) || 211 (((a.binary | b.binary) & 0x7FFFFFFF) == 0)); 212 212 } 213 213 … … 219 219 * @return 1 if both floats are equal, 0 otherwise. 220 220 */ 221 int is _float64_eq(float64 a, float64 b)221 int isFloat64eq(float64 a, float64 b) 222 222 { 223 223 /* a equals to b or both are zeros (with any sign) */ 224 return ((a.bin == b.bin) ||225 (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0));224 return ((a.binary == b.binary) || 225 (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0)); 226 226 } 227 227 … … 233 233 * @return 1 if both floats are equal, 0 otherwise. 234 234 */ 235 int is _float128_eq(float128 a, float128 b)235 int isFloat128eq(float128 a, float128 b) 236 236 { 237 237 uint64_t tmp_hi; 238 238 uint64_t tmp_lo; 239 239 240 240 /* both are zeros (with any sign) */ 241 or128(a.bin .hi, a.bin.lo,242 b.bin .hi, b.bin.lo, &tmp_hi, &tmp_lo);241 or128(a.binary.hi, a.binary.lo, 242 b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo); 243 243 and128(tmp_hi, tmp_lo, 244 244 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); … … 246 246 247 247 /* a equals to b */ 248 int are_equal = eq128(a.bin .hi, a.bin.lo, b.bin.hi, b.bin.lo);249 248 int are_equal = eq128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo); 249 250 250 return are_equal || both_zero; 251 251 } … … 258 258 * @return 1 if a is lower than b, 0 otherwise. 259 259 */ 260 int is_float32_lt(float32 a, float32 b) 261 { 262 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { 263 /* +- zeroes */ 264 return 0; 260 int isFloat32lt(float32 a, float32 b) 261 { 262 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) { 263 return 0; /* +- zeroes */ 265 264 } 266 265 267 266 if ((a.parts.sign) && (b.parts.sign)) { 268 267 /* if both are negative, smaller is that with greater binary value */ 269 return (a.bin > b.bin);268 return (a.binary > b.binary); 270 269 } 271 270 272 /* 273 * lets negate signs - now will be positive numbers always 274 * bigger than negative (first bit will be set for unsigned 275 * integer comparison) 276 */ 277 a.parts.sign = !a.parts.sign; 278 b.parts.sign = !b.parts.sign; 279 return (a.bin < b.bin); 271 /* lets negate signs - now will be positive numbers allways bigger than 272 * negative (first bit will be set for unsigned integer comparison) */ 273 a.parts.sign = !a.parts.sign; 274 b.parts.sign = !b.parts.sign; 275 return (a.binary < b.binary); 280 276 } 281 277 … … 287 283 * @return 1 if a is lower than b, 0 otherwise. 288 284 */ 289 int is_float64_lt(float64 a, float64 b) 290 { 291 if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) { 292 /* +- zeroes */ 293 return 0; 294 } 295 285 int isFloat64lt(float64 a, float64 b) 286 { 287 if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) { 288 return 0; /* +- zeroes */ 289 } 290 296 291 if ((a.parts.sign) && (b.parts.sign)) { 297 292 /* if both are negative, smaller is that with greater binary value */ 298 return (a.bin > b.bin); 299 } 300 301 /* 302 * lets negate signs - now will be positive numbers always 303 * bigger than negative (first bit will be set for unsigned 304 * integer comparison) 305 */ 306 a.parts.sign = !a.parts.sign; 307 b.parts.sign = !b.parts.sign; 308 return (a.bin < b.bin); 293 return (a.binary > b.binary); 294 } 295 296 /* lets negate signs - now will be positive numbers allways bigger than 297 * negative (first bit will be set for unsigned integer comparison) */ 298 a.parts.sign = !a.parts.sign; 299 b.parts.sign = !b.parts.sign; 300 return (a.binary < b.binary); 309 301 } 310 302 … … 316 308 * @return 1 if a is lower than b, 0 otherwise. 317 309 */ 318 int is _float128_lt(float128 a, float128 b)310 int isFloat128lt(float128 a, float128 b) 319 311 { 320 312 uint64_t tmp_hi; 321 313 uint64_t tmp_lo; 322 323 or128(a.bin .hi, a.bin.lo,324 b.bin .hi, b.bin.lo, &tmp_hi, &tmp_lo);314 315 or128(a.binary.hi, a.binary.lo, 316 b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo); 325 317 and128(tmp_hi, tmp_lo, 326 318 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 327 319 if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) { 328 /* +- zeroes */ 329 return 0; 330 } 331 320 return 0; /* +- zeroes */ 321 } 322 332 323 if ((a.parts.sign) && (b.parts.sign)) { 333 324 /* if both are negative, smaller is that with greater binary value */ 334 return lt128(b.bin.hi, b.bin.lo, a.bin.hi, a.bin.lo); 335 } 336 337 /* 338 * lets negate signs - now will be positive numbers always 339 * bigger than negative (first bit will be set for unsigned 340 * integer comparison) 341 */ 342 a.parts.sign = !a.parts.sign; 343 b.parts.sign = !b.parts.sign; 344 return lt128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo); 325 return lt128(b.binary.hi, b.binary.lo, a.binary.hi, a.binary.lo); 326 } 327 328 /* lets negate signs - now will be positive numbers allways bigger than 329 * negative (first bit will be set for unsigned integer comparison) */ 330 a.parts.sign = !a.parts.sign; 331 b.parts.sign = !b.parts.sign; 332 return lt128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo); 345 333 } 346 334 … … 352 340 * @return 1 if a is greater than b, 0 otherwise. 353 341 */ 354 int is_float32_gt(float32 a, float32 b) 355 { 356 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { 357 /* zeroes are equal with any sign */ 358 return 0; 342 int isFloat32gt(float32 a, float32 b) 343 { 344 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) { 345 return 0; /* zeroes are equal with any sign */ 359 346 } 360 347 361 348 if ((a.parts.sign) && (b.parts.sign)) { 362 349 /* if both are negative, greater is that with smaller binary value */ 363 return (a.bin < b.bin);350 return (a.binary < b.binary); 364 351 } 365 352 366 /* 367 * lets negate signs - now will be positive numbers always 368 * bigger than negative (first bit will be set for unsigned 369 * integer comparison) 370 */ 371 a.parts.sign = !a.parts.sign; 372 b.parts.sign = !b.parts.sign; 373 return (a.bin > b.bin); 353 /* lets negate signs - now will be positive numbers allways bigger than 354 * negative (first bit will be set for unsigned integer comparison) */ 355 a.parts.sign = !a.parts.sign; 356 b.parts.sign = !b.parts.sign; 357 return (a.binary > b.binary); 374 358 } 375 359 … … 381 365 * @return 1 if a is greater than b, 0 otherwise. 382 366 */ 383 int is_float64_gt(float64 a, float64 b) 384 { 385 if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) { 386 /* zeroes are equal with any sign */ 387 return 0; 388 } 389 367 int isFloat64gt(float64 a, float64 b) 368 { 369 if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) { 370 return 0; /* zeroes are equal with any sign */ 371 } 372 390 373 if ((a.parts.sign) && (b.parts.sign)) { 391 374 /* if both are negative, greater is that with smaller binary value */ 392 return (a.bin < b.bin); 393 } 394 395 /* 396 * lets negate signs - now will be positive numbers always 397 * bigger than negative (first bit will be set for unsigned 398 * integer comparison) 399 */ 400 a.parts.sign = !a.parts.sign; 401 b.parts.sign = !b.parts.sign; 402 return (a.bin > b.bin); 375 return (a.binary < b.binary); 376 } 377 378 /* lets negate signs - now will be positive numbers allways bigger than 379 * negative (first bit will be set for unsigned integer comparison) */ 380 a.parts.sign = !a.parts.sign; 381 b.parts.sign = !b.parts.sign; 382 return (a.binary > b.binary); 403 383 } 404 384 … … 410 390 * @return 1 if a is greater than b, 0 otherwise. 411 391 */ 412 int is _float128_gt(float128 a, float128 b)392 int isFloat128gt(float128 a, float128 b) 413 393 { 414 394 uint64_t tmp_hi; 415 395 uint64_t tmp_lo; 416 417 or128(a.bin .hi, a.bin.lo,418 b.bin .hi, b.bin.lo, &tmp_hi, &tmp_lo);396 397 or128(a.binary.hi, a.binary.lo, 398 b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo); 419 399 and128(tmp_hi, tmp_lo, 420 400 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 421 401 if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) { 422 /* zeroes are equal with any sign */ 423 return 0; 424 } 425 402 return 0; /* zeroes are equal with any sign */ 403 } 404 426 405 if ((a.parts.sign) && (b.parts.sign)) { 427 406 /* if both are negative, greater is that with smaller binary value */ 428 return lt128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo); 429 } 430 431 /* 432 * lets negate signs - now will be positive numbers always 433 * bigger than negative (first bit will be set for unsigned 434 * integer comparison) 435 */ 436 a.parts.sign = !a.parts.sign; 437 b.parts.sign = !b.parts.sign; 438 return lt128(b.bin.hi, b.bin.lo, a.bin.hi, a.bin.lo); 407 return lt128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo); 408 } 409 410 /* lets negate signs - now will be positive numbers allways bigger than 411 * negative (first bit will be set for unsigned integer comparison) */ 412 a.parts.sign = !a.parts.sign; 413 b.parts.sign = !b.parts.sign; 414 return lt128(b.binary.hi, b.binary.lo, a.binary.hi, a.binary.lo); 439 415 } 440 416
Note:
See TracChangeset
for help on using the changeset viewer.