Click here to Skip to main content
11,805,035 members (60,405 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET .NET4 mathematics
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
Joezer BH38.3K
Edited 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 at 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 at 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
0 OriginalGriff 315
1 Richard Deeming 200
2 Sergey Alexandrovich Kryukov 168
3 CPallini 160
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 16 May 2013
Copyright © CodeProject, 1999-2015
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