Static decimal members Static decimal members
Posts 1 to 6 of 6
  1. #1

    Prehistoric

    thunderlizard is too good to be a permie


    Join Date
    Jul 2005
    Posts
    5,826

    Default 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. #2

    Richer than sasguru

    DimPrawn is a fount of knowledge

    DimPrawn's Avatar
    Join Date
    Jul 2005
    Location
    Brexit Britain
    Posts
    34,551

    Default

    Quote 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.
    I was miserable and depressed, but CUK turned it all around. Now I'm depressed and miserable.

  3. #3

    Prehistoric

    thunderlizard is too good to be a permie


    Join Date
    Jul 2005
    Posts
    5,826

    Default

    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)
    {
    }

  4. #4

    Banned

    Diestl has no reputation

    Diestl's Avatar
    Join Date
    Jul 2006
    Posts
    1,128

    Default

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

  5. #5

    Prehistoric

    thunderlizard is too good to be a permie


    Join Date
    Jul 2005
    Posts
    5,826

    Default

    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.

  6. #6

    My post count is Majestic

    NickFitz has reached the peak. Play again?

    NickFitz's Avatar
    Join Date
    Jun 2007
    Location
    Your local branch
    Posts
    45,773

    Default

    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 ! ] ;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •