Rev 865 | Rev 875 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 865 | Rev 874 | ||
|---|---|---|---|
| Line 27... | Line 27... | ||
| 27 | */ |
27 | */ |
| 28 | 28 | ||
| 29 | #include "sftypes.h" |
29 | #include "sftypes.h" |
| 30 | #include "conversion.h" |
30 | #include "conversion.h" |
| 31 | #include "comparison.h" |
31 | #include "comparison.h" |
| - | 32 | #include "common.h" |
|
| 32 | 33 | ||
| 33 | float64 convertFloat32ToFloat64(float32 a) |
34 | float64 convertFloat32ToFloat64(float32 a) |
| 34 | { |
35 | { |
| 35 | float64 result; |
36 | float64 result; |
| 36 | __u64 frac; |
37 | __u64 frac; |
| Line 383... | Line 384... | ||
| 383 | return MAX_INT32; |
384 | return MAX_INT32; |
| 384 | } |
385 | } |
| 385 | return (__s32)_float64_to_uint64_helper(a); |
386 | return (__s32)_float64_to_uint64_helper(a); |
| 386 | } |
387 | } |
| 387 | 388 | ||
| - | 389 | ||
| - | 390 | /** Convert unsigned integer to float32 |
|
| - | 391 | * |
|
| - | 392 | * |
|
| - | 393 | */ |
|
| - | 394 | float32 uint32_to_float32(__u32 i) |
|
| - | 395 | { |
|
| - | 396 | int counter; |
|
| - | 397 | __s32 exp; |
|
| - | 398 | float32 result; |
|
| - | 399 | ||
| - | 400 | result.parts.sign = 0; |
|
| - | 401 | result.parts.fraction = 0; |
|
| - | 402 | ||
| - | 403 | counter = countZeroes32(i); |
|
| - | 404 | ||
| - | 405 | exp = FLOAT32_BIAS + 32 - counter - 1; |
|
| - | 406 | ||
| - | 407 | if (counter == 32) { |
|
| - | 408 | result.binary = 0; |
|
| - | 409 | return result; |
|
| - | 410 | } |
|
| - | 411 | ||
| - | 412 | if (counter > 0) { |
|
| - | 413 | i <<= counter - 1; |
|
| - | 414 | } else { |
|
| - | 415 | i >>= 1; |
|
| - | 416 | } |
|
| - | 417 | ||
| - | 418 | roundFloat32(&exp, &i); |
|
| - | 419 | ||
| - | 420 | result.parts.fraction = i >> 7; |
|
| - | 421 | result.parts.exp = exp; |
|
| - | 422 | ||
| - | 423 | return result; |
|
| - | 424 | } |
|
| 388 | 425 | ||
| - | 426 | float32 int32_to_float32(__s32 i) |
|
| - | 427 | { |
|
| - | 428 | float32 result; |
|
| - | 429 | ||
| - | 430 | if (i < 0) { |
|
| - | 431 | result = uint32_to_float32((__u32)(-i)); |
|
| - | 432 | } else { |
|
| - | 433 | result = uint32_to_float32((__u32)i); |
|
| - | 434 | } |
|
| - | 435 | ||
| - | 436 | result.parts.sign = i < 0; |
|
| - | 437 | ||
| - | 438 | return result; |
|
| - | 439 | } |
|
| - | 440 | ||
| - | 441 | ||
| - | 442 | float32 uint64_to_float32(__u64 i) |
|
| - | 443 | { |
|
| - | 444 | } |
|
| - | 445 | ||
| - | 446 | float32 int64_to_float32(__s64 i) |
|
| - | 447 | { |
|
| - | 448 | float32 result; |
|
| - | 449 | ||
| - | 450 | if (i < 0) { |
|
| - | 451 | result = uint64_to_float32((__u64)(-i)); |
|
| - | 452 | } else { |
|
| - | 453 | result = uint64_to_float32((__u64)i); |
|
| - | 454 | } |
|
| - | 455 | ||
| - | 456 | result.parts.sign = i < 0; |
|
| - | 457 | ||
| - | 458 | return result; |
|
| - | 459 | } |
|