• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Static decimal members

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Static decimal members

    Obscure bit of .NET that I hadn't noticed in my many years of it:
    there are static members for decimal.One, decimal.Zero and decimal.MinusOne.

    Prudent of Microsoft to have reserved themselves the ability to adopt their own definitions of these numbers in future: but if they want to change any other numbers they're stuck.

    StackOverflow is normally great, but it struggles with this one:
    http://stackoverflow.com/questions/7...-minusone-in-c

    #2
    Originally posted by thunderlizard View Post
    Obscure bit of .NET that I hadn't noticed in my many years of it:
    there are static members for decimal.One, decimal.Zero and decimal.MinusOne.

    Prudent of Microsoft to have reserved themselves the ability to adopt their own definitions of these numbers in future: but if they want to change any other numbers they're stuck.

    StackOverflow is normally great, but it struggles with this one:
    http://stackoverflow.com/questions/7...-minusone-in-c
    Don't tell me you've been using the plain vanilla 0,1 and -1 in your code!

    It's a bit like "" vs string.Empty

    It's readability for squinty eyed techies.

    Comment


      #3
      I know, I've been using "magic numbers" all this time and am heartily sorry!

      From here on in, it's going to be:

      Code:
      for(decimal d=decimal.Zero; d<things.Count; d+=decimal.One)
      {
      }

      Comment


        #4
        So they can at a later date put a better optimized 1 in place and you wont have to change your code.

        Comment


          #5
          You think so? That is as plausible as anything I suppose. But something tells me that the people worried about the performance of their 1's aren't using .NET in the first place.

          Comment


            #6
            Forth (FORTH if you prefer) used to define 0, 1, 2, -1 and -2 as constants - it could be a win for an indirect-threaded implementation running on something like a 6809 or a Z80.

            Of course, there was nothing to stop you redefining them:

            Code:
            : 0 ( - n) ." Hello World" 3 ;
            
            : 1 ( - n) CAKE BAKE  42 ;
            
            : -1 ( - n)  R> DROP [ BASE @ DECIMAL 36 BASE ! ] FAIL [ BASE ! ] ;

            Comment

            Working...
            X