tgbaodeeptry's blog

By tgbaodeeptry, history, 4 years ago, In English

Assume I have 3 long long varables a, b and n. And them are approximately (max long long)( 2.10^18 ).

So, are there any ways that I can check if a + b is larger than n?

Thanks so much guys

  • Vote: I like it
  • +22
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +54 Vote: I do not like it

Yes. Since a + b > n means a > n - b you can just check that.

»
4 years ago, # |
  Vote: I like it -57 Vote: I do not like it

Convert them all to double.

»
4 years ago, # |
  Vote: I like it +21 Vote: I do not like it
»
4 years ago, # |
  Vote: I like it -8 Vote: I do not like it

ive seen people use logs like log(a) + log(b) >= 18 or something along those lines. personally I just ll overflow each time so I don't use it

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Thats for multiplication I guess.