Rev 857 | Rev 874 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 857 | Rev 865 | ||
---|---|---|---|
Line 205... | Line 205... | ||
205 | } |
205 | } |
206 | return _float32_to_uint32_helper(a); |
206 | return _float32_to_uint32_helper(a); |
207 | } |
207 | } |
208 | 208 | ||
209 | 209 | ||
- | 210 | /** Helping procedure for converting float64 to uint64 |
|
- | 211 | * @param a floating point number in normalized form (no NaNs or Inf are checked ) |
|
- | 212 | * @return unsigned integer |
|
- | 213 | */ |
|
- | 214 | static __u64 _float64_to_uint64_helper(float64 a) |
|
- | 215 | { |
|
- | 216 | __u64 frac; |
|
- | 217 | ||
- | 218 | if (a.parts.exp < FLOAT64_BIAS) { |
|
- | 219 | /*TODO: rounding*/ |
|
- | 220 | return 0; |
|
- | 221 | } |
|
- | 222 | ||
- | 223 | frac = a.parts.fraction; |
|
- | 224 | ||
- | 225 | frac |= FLOAT64_HIDDEN_BIT_MASK; |
|
- | 226 | /* shift fraction to left so hidden bit will be the most significant bit */ |
|
- | 227 | frac <<= 64 - FLOAT64_FRACTION_SIZE - 1; |
|
- | 228 | ||
- | 229 | frac >>= 64 - (a.parts.exp - FLOAT64_BIAS) - 1; |
|
- | 230 | if ((a.parts.sign == 1) && (frac != 0)) { |
|
- | 231 | frac = ~frac; |
|
- | 232 | ++frac; |
|
- | 233 | } |
|
- | 234 | ||
- | 235 | return frac; |
|
- | 236 | } |
|
- | 237 | ||
- | 238 | /* Convert float to unsigned int64 |
|
- | 239 | * FIXME: Im not sure what to return if overflow/underflow happens |
|
- | 240 | * - now its the biggest or the smallest int |
|
- | 241 | */ |
|
- | 242 | __u64 float64_to_uint64(float64 a) |
|
- | 243 | { |
|
- | 244 | if (isFloat64NaN(a)) { |
|
- | 245 | return MAX_UINT64; |
|
- | 246 | } |
|
- | 247 | ||
- | 248 | if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { |
|
- | 249 | if (a.parts.sign) { |
|
- | 250 | return MIN_UINT64; |
|
- | 251 | } |
|
- | 252 | return MAX_UINT64; |
|
- | 253 | } |
|
- | 254 | ||
- | 255 | return _float64_to_uint64_helper(a); |
|
- | 256 | } |
|
- | 257 | ||
- | 258 | /* Convert float to signed int64 |
|
- | 259 | * FIXME: Im not sure what to return if overflow/underflow happens |
|
- | 260 | * - now its the biggest or the smallest int |
|
- | 261 | */ |
|
- | 262 | __s64 float64_to_int64(float64 a) |
|
- | 263 | { |
|
- | 264 | if (isFloat64NaN(a)) { |
|
- | 265 | return MAX_INT64; |
|
- | 266 | } |
|
- | 267 | ||
- | 268 | if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { |
|
- | 269 | if (a.parts.sign) { |
|
- | 270 | return MIN_INT64; |
|
- | 271 | } |
|
- | 272 | return MAX_INT64; |
|
- | 273 | } |
|
- | 274 | return _float64_to_uint64_helper(a); |
|
- | 275 | } |
|
- | 276 | ||
- | 277 | ||
- | 278 | ||
- | 279 | ||
- | 280 | ||
- | 281 | /** Helping procedure for converting float32 to uint64 |
|
- | 282 | * @param a floating point number in normalized form (no NaNs or Inf are checked ) |
|
- | 283 | * @return unsigned integer |
|
- | 284 | */ |
|
- | 285 | static __u64 _float32_to_uint64_helper(float32 a) |
|
- | 286 | { |
|
- | 287 | __u64 frac; |
|
- | 288 | ||
- | 289 | if (a.parts.exp < FLOAT32_BIAS) { |
|
- | 290 | /*TODO: rounding*/ |
|
- | 291 | return 0; |
|
- | 292 | } |
|
- | 293 | ||
- | 294 | frac = a.parts.fraction; |
|
- | 295 | ||
- | 296 | frac |= FLOAT32_HIDDEN_BIT_MASK; |
|
- | 297 | /* shift fraction to left so hidden bit will be the most significant bit */ |
|
- | 298 | frac <<= 64 - FLOAT32_FRACTION_SIZE - 1; |
|
- | 299 | ||
- | 300 | frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1; |
|
- | 301 | if ((a.parts.sign == 1) && (frac != 0)) { |
|
- | 302 | frac = ~frac; |
|
- | 303 | ++frac; |
|
- | 304 | } |
|
- | 305 | ||
- | 306 | return frac; |
|
- | 307 | } |
|
- | 308 | ||
- | 309 | /* Convert float to unsigned int64 |
|
- | 310 | * FIXME: Im not sure what to return if overflow/underflow happens |
|
- | 311 | * - now its the biggest or the smallest int |
|
- | 312 | */ |
|
- | 313 | __u64 float32_to_uint64(float32 a) |
|
- | 314 | { |
|
- | 315 | if (isFloat32NaN(a)) { |
|
- | 316 | return MAX_UINT64; |
|
- | 317 | } |
|
- | 318 | ||
- | 319 | if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { |
|
- | 320 | if (a.parts.sign) { |
|
- | 321 | return MIN_UINT64; |
|
- | 322 | } |
|
- | 323 | return MAX_UINT64; |
|
- | 324 | } |
|
- | 325 | ||
- | 326 | return _float32_to_uint64_helper(a); |
|
- | 327 | } |
|
- | 328 | ||
- | 329 | /* Convert float to signed int64 |
|
- | 330 | * FIXME: Im not sure what to return if overflow/underflow happens |
|
- | 331 | * - now its the biggest or the smallest int |
|
- | 332 | */ |
|
- | 333 | __s64 float32_to_int64(float32 a) |
|
- | 334 | { |
|
- | 335 | if (isFloat32NaN(a)) { |
|
- | 336 | return MAX_INT64; |
|
- | 337 | } |
|
- | 338 | ||
- | 339 | if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { |
|
- | 340 | if (a.parts.sign) { |
|
- | 341 | return (MIN_INT64); |
|
- | 342 | } |
|
- | 343 | return MAX_INT64; |
|
- | 344 | } |
|
- | 345 | return _float32_to_uint64_helper(a); |
|
- | 346 | } |
|
- | 347 | ||
- | 348 | ||
- | 349 | /* Convert float64 to unsigned int32 |
|
- | 350 | * FIXME: Im not sure what to return if overflow/underflow happens |
|
- | 351 | * - now its the biggest or the smallest int |
|
- | 352 | */ |
|
- | 353 | __u32 float64_to_uint32(float64 a) |
|
- | 354 | { |
|
- | 355 | if (isFloat64NaN(a)) { |
|
- | 356 | return MAX_UINT32; |
|
- | 357 | } |
|
- | 358 | ||
- | 359 | if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { |
|
- | 360 | if (a.parts.sign) { |
|
- | 361 | return MIN_UINT32; |
|
- | 362 | } |
|
- | 363 | return MAX_UINT32; |
|
- | 364 | } |
|
- | 365 | ||
- | 366 | return (__u32)_float64_to_uint64_helper(a); |
|
- | 367 | } |
|
- | 368 | ||
- | 369 | /* Convert float64 to signed int32 |
|
- | 370 | * FIXME: Im not sure what to return if overflow/underflow happens |
|
- | 371 | * - now its the biggest or the smallest int |
|
- | 372 | */ |
|
- | 373 | __s32 float64_to_int32(float64 a) |
|
- | 374 | { |
|
- | 375 | if (isFloat64NaN(a)) { |
|
- | 376 | return MAX_INT32; |
|
- | 377 | } |
|
- | 378 | ||
- | 379 | if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { |
|
- | 380 | if (a.parts.sign) { |
|
- | 381 | return MIN_INT32; |
|
- | 382 | } |
|
- | 383 | return MAX_INT32; |
|
- | 384 | } |
|
- | 385 | return (__s32)_float64_to_uint64_helper(a); |
|
- | 386 | } |
|
- | 387 | ||
210 | 388 |