Click here to Skip to main content
13,092,862 members (97,749 online)
Rate this:
Please Sign up or sign in to 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 9-Apr-13 21:59pm
Updated 16-May-13 1:02am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^].
Edo Tzumer 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Have a look here:[^]
The StackOverflow question is a question about why NaN is only available for doubles, but it also applies to PositiveInfinity.
Edo Tzumer 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 16 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100