Click here to Skip to main content
15,888,129 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
MS chose to insert a representation of Infinity in Double and Float but not in Decimal and Int64?

You have:
Double.PositiveInfinity & Float.PositiveInfinity (as well as Double.Epsilon & Float.Epsilon) which are missing in Decimal.

Q: Why?


Moreover: I understand the concept of decimal being basically designed more for currency operations and other "real world" calculations.

But being that doesn't really explain my question.
The reason is that even decimal and Int64 has it's limits of course,
these limits
in Int64 if you multiply MaxValue by MaxValue you get 1 !!!!
in Decimal it throws an exception. (which I may live with)

You could easily implement Infinity in both.
Arguably an exception is a desired response, but the Int64 behavior is totally silly in my opinion.
Posted
Updated 16-May-13 1:02am
v5

The short answer is 'because that's what the standard says'; IEEE floating point defines infinities and NaNs, whereas the integer standards don't. Decimal, despite having a floating point in the most literal sense of that term, is based on the integer standards (and obviously long is a native integer type). The 'special' bit patterns are typically 'most bits on' and as such would represent small negative numbers in an integer type.

You can alter the overflow behaviour of native types in .Net with the checked{...} or unchecked{...} constructs, with a compiler option setting the default: see MSDN[^].
 
Share this answer
 
Comments
Joezer BH 16-May-13 7:40am    
Quote: "because that's what the standard says"

I am inclined to accept this answer, which is probably a typical MS answer: highly descriptive and yet utterly useless.
:laugh:
Hi,

Have a look here:
http://stackoverflow.com/questions/986268/why-is-nan-not-a-number-only-available-for-doubles[^]
The StackOverflow question is a question about why NaN is only available for doubles, but it also applies to PositiveInfinity.
 
Share this answer
 
v2
Comments
Joezer BH 10-Apr-13 4:18am    
See question update

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900