Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. operator overload

operator overload

Scheduled Pinned Locked Moved C#
questioncsharphelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sduhd
    wrote on last edited by
    #1

    look at the lines: double x = double.MaxValue; double y = double.MaxValue; double what = (x+y)-y; if c# select the double operator+(double,double), then what should be "PositiveInfinity"; but it is double.MaxValue! Why does this happen? Is there a decimal operator + (double,double)? If there is, then there should be no " double operator +(double,double)". Who knows the fact? Please help. Thanks.

    G 1 Reply Last reply
    0
    • S sduhd

      look at the lines: double x = double.MaxValue; double y = double.MaxValue; double what = (x+y)-y; if c# select the double operator+(double,double), then what should be "PositiveInfinity"; but it is double.MaxValue! Why does this happen? Is there a decimal operator + (double,double)? If there is, then there should be no " double operator +(double,double)". Who knows the fact? Please help. Thanks.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      I think that the compiler optimizes x+y-y to x. --- b { font-weight: normal; }

      S 1 Reply Last reply
      0
      • G Guffa

        I think that the compiler optimizes x+y-y to x. --- b { font-weight: normal; }

        S Offline
        S Offline
        sduhd
        wrote on last edited by
        #3

        nope. (x+y)-y got the same result.

        G 1 Reply Last reply
        0
        • S sduhd

          nope. (x+y)-y got the same result.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Here is the compiled code: x = double.MaxValue; 00000020 mov dword ptr [ebp-10h],0FFFFFFFFh 00000027 mov dword ptr [ebp-0Ch],7FEFFFFFh y = double.MaxValue; 0000002e mov dword ptr [ebp-18h],0FFFFFFFFh 00000035 mov dword ptr [ebp-14h],7FEFFFFFh z = x + y - y; 0000003c fld qword ptr [ebp-10h] 0000003f fadd qword ptr [ebp-18h] 00000042 fsub qword ptr [ebp-18h] 00000045 fstp qword ptr [ebp-20h] The actual calculation is done in the FPU, storing the result of the first calculation internally. It looks like the datatype used internally can handle larger values than a double, as the result of the calculation is correct. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups