Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Integer to Floating-Point conversions

Thread Tools

Integer to Floating-Point conversions

Patricia Shanahan
Posts: n/a
Chris Uppal wrote:
> Patricia Shanahan wrote:
>>If rounded is not an exact power of two, the truncation has a mantissa
>>one less than rounded. If it is an exact power of two, it has an
>>exponent one less than rounded, and mantissa all ones. Either way,
>>subtracting one from the rounded bit pattern gets the bit pattern for

> Ah, I see. The IEEE fp layout is subtle.
> Thank you.
>>If you prefer to avoid double, just do the abs in int:

> Unfotunately, the comparison doesn't work for Integer.MAX_VALUE, nor for values
> near Integer.MIN_VALUE. Two example failure cases are:

> I find the negative output from Math.abs() particularly entertaining

Good point. Shows the folly of not testing at least the maximum and
minimum value, as well as some ordinary values.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Arithmetic conversions and integer constants Spiros Bousbouras C Programming 6 01-14-2009 04:30 PM
pointer to integer to pointer conversions C Programming 11 05-08-2008 12:52 PM
Why do integer-to-double conversions do not happen in printf C Programming 17 10-29-2006 12:49 PM
Integer to "string" conversions C Programming 13 10-02-2006 05:48 AM
Pointer conversions and Data types conversions C Programming 10 08-05-2005 09:51 AM