Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# maths .NET4
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 22:59pm
Edited 16-May-13 2:02am
v5
Rate this: bad
good
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[^].
  Permalink  
Comments
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.
:laugh:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
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 277
1 Maciej Los 240
2 DamithSL 200
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 16 May 2013
Copyright © CodeProject, 1999-2014
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