Changes in uspace/lib/softfloat/generic/comparison.c [c67aff2:88d5c1e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/generic/comparison.c
rc67aff2 r88d5c1e 45 45 * @return 1 if float is NaN, 0 otherwise. 46 46 */ 47 int is Float32NaN(float32 f)47 int is_float32_nan(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 Float64NaN(float64 d)60 int is_float64_nan(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 Float128NaN(float128 ld)73 int is_float128_nan(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 Float32SigNaN(float32 f)86 int is_float32_signan(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 Float64SigNaN(float64 d)100 int is_float64_signan(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 Float128SigNaN(float128 ld)114 int is_float128_signan(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 Float32Infinity(float32 f)130 int is_float32_infinity(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 Float64Infinity(float64 d)142 int is_float64_infinity(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 Float128Infinity(float128 ld)154 int is_float128_infinity(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 Float32Zero(float32 f)168 { 169 return (((f.bin ary) & 0x7FFFFFFF) == 0);167 int is_float32_zero(float32 f) 168 { 169 return (((f.bin) & 0x7FFFFFFF) == 0); 170 170 } 171 171 … … 176 176 * @return 1 if float is zero, 0 otherwise. 177 177 */ 178 int is Float64Zero(float64 d)179 { 180 return (((d.bin ary) & 0x7FFFFFFFFFFFFFFFll) == 0);178 int is_float64_zero(float64 d) 179 { 180 return (((d.bin) & 0x7FFFFFFFFFFFFFFFll) == 0); 181 181 } 182 182 … … 187 187 * @return 1 if float is zero, 0 otherwise. 188 188 */ 189 int is Float128Zero(float128 ld)189 int is_float128_zero(float128 ld) 190 190 { 191 191 uint64_t tmp_hi; 192 192 uint64_t tmp_lo; 193 194 and128(ld.bin ary.hi, ld.binary.lo,193 194 and128(ld.bin.hi, ld.bin.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 Float32eq(float32 a, float32 b)207 int is_float32_eq(float32 a, float32 b) 208 208 { 209 209 /* a equals to b or both are zeros (with any sign) */ 210 return ((a.bin ary == b.binary) ||211 (((a.bin ary | b.binary) & 0x7FFFFFFF) == 0));210 return ((a.bin == b.bin) || 211 (((a.bin | b.bin) & 0x7FFFFFFF) == 0)); 212 212 } 213 213 … … 219 219 * @return 1 if both floats are equal, 0 otherwise. 220 220 */ 221 int is Float64eq(float64 a, float64 b)221 int is_float64_eq(float64 a, float64 b) 222 222 { 223 223 /* a equals to b or both are zeros (with any sign) */ 224 return ((a.bin ary == b.binary) ||225 (((a.bin ary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0));224 return ((a.bin == b.bin) || 225 (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0)); 226 226 } 227 227 … … 233 233 * @return 1 if both floats are equal, 0 otherwise. 234 234 */ 235 int is Float128eq(float128 a, float128 b)235 int is_float128_eq(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 ary.hi, a.binary.lo,242 b.bin ary.hi, b.binary.lo, &tmp_hi, &tmp_lo);241 or128(a.bin.hi, a.bin.lo, 242 b.bin.hi, b.bin.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 ary.hi, a.binary.lo, b.binary.hi, b.binary.lo);249 248 int are_equal = eq128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.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 isFloat32lt(float32 a, float32 b) 261 { 262 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) { 263 return 0; /* +- zeroes */ 260 int is_float32_lt(float32 a, float32 b) 261 { 262 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { 263 /* +- zeroes */ 264 return 0; 264 265 } 265 266 266 267 if ((a.parts.sign) && (b.parts.sign)) { 267 268 /* if both are negative, smaller is that with greater binary value */ 268 return (a.binary > b.binary); 269 } 270 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); 269 return (a.bin > b.bin); 270 } 271 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); 276 280 } 277 281 … … 283 287 * @return 1 if a is lower than b, 0 otherwise. 284 288 */ 285 int isFloat64lt(float64 a, float64 b) 286 { 287 if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) { 288 return 0; /* +- zeroes */ 289 } 290 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 291 296 if ((a.parts.sign) && (b.parts.sign)) { 292 297 /* if both are negative, smaller is that with greater binary value */ 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); 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); 301 309 } 302 310 … … 308 316 * @return 1 if a is lower than b, 0 otherwise. 309 317 */ 310 int is Float128lt(float128 a, float128 b)318 int is_float128_lt(float128 a, float128 b) 311 319 { 312 320 uint64_t tmp_hi; 313 321 uint64_t tmp_lo; 314 315 or128(a.bin ary.hi, a.binary.lo,316 b.bin ary.hi, b.binary.lo, &tmp_hi, &tmp_lo);322 323 or128(a.bin.hi, a.bin.lo, 324 b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo); 317 325 and128(tmp_hi, tmp_lo, 318 326 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 319 327 if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) { 320 return 0; /* +- zeroes */ 321 } 322 328 /* +- zeroes */ 329 return 0; 330 } 331 323 332 if ((a.parts.sign) && (b.parts.sign)) { 324 333 /* if both are negative, smaller is that with greater binary value */ 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); 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); 333 345 } 334 346 … … 340 352 * @return 1 if a is greater than b, 0 otherwise. 341 353 */ 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 */ 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; 346 359 } 347 360 348 361 if ((a.parts.sign) && (b.parts.sign)) { 349 362 /* if both are negative, greater is that with smaller binary value */ 350 return (a.binary < b.binary); 351 } 352 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); 363 return (a.bin < b.bin); 364 } 365 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); 358 374 } 359 375 … … 365 381 * @return 1 if a is greater than b, 0 otherwise. 366 382 */ 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 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 373 390 if ((a.parts.sign) && (b.parts.sign)) { 374 391 /* if both are negative, greater is that with smaller binary value */ 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); 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); 383 403 } 384 404 … … 390 410 * @return 1 if a is greater than b, 0 otherwise. 391 411 */ 392 int is Float128gt(float128 a, float128 b)412 int is_float128_gt(float128 a, float128 b) 393 413 { 394 414 uint64_t tmp_hi; 395 415 uint64_t tmp_lo; 396 397 or128(a.bin ary.hi, a.binary.lo,398 b.bin ary.hi, b.binary.lo, &tmp_hi, &tmp_lo);416 417 or128(a.bin.hi, a.bin.lo, 418 b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo); 399 419 and128(tmp_hi, tmp_lo, 400 420 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 401 421 if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) { 402 return 0; /* zeroes are equal with any sign */ 403 } 404 422 /* zeroes are equal with any sign */ 423 return 0; 424 } 425 405 426 if ((a.parts.sign) && (b.parts.sign)) { 406 427 /* if both are negative, greater is that with smaller binary value */ 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); 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); 415 439 } 416 440
Note:
See TracChangeset
for help on using the changeset viewer.