Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37938

Re: Can Java 8 do exact arithmetic as in C#

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Can Java 8 do exact arithmetic as in C#
Date Mon, 8 Jan 2018 08:42:50 -0500
Organization A noiseless patient Spider
Lines 35
Message-ID <p2vsgr$2f1$1@dont-email.me> (permalink)
References <0ef8b3c0-e45c-4624-a8b8-2bdc67135380@googlegroups.com> <p2vnnj$cqa$1@news.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Mon, 8 Jan 2018 13:42:51 -0000 (UTC)
Injection-Info h2725194.stratoserver.net; posting-host="9abe5c43625e8f62c6ccbf84f7874f8c"; logging-data="2529"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hfsIXDV/ouXVgC/xaSsVm"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2
In-Reply-To <p2vnnj$cqa$1@news.albasani.net>
Content-Language en-US
Cancel-Lock sha1:PVvgcWoGWP/8AXpxXQEeZvt4LKQ=
Xref csiph.com comp.lang.java.programmer:37938

Show key headers only | View raw


On 1/8/2018 7:21 AM, j4n bur53 wrote:
> The source code is available, its a pure Java
> implementation, no native code. For example addExact
> is implemented as follows:
> 
>      /**
>       * Returns the sum of its arguments,
>       * throwing an exception if the result overflows an {@code int}.
>       *
>       * @param x the first value
>       * @param y the second value
>       * @return the result
>       * @throws ArithmeticException if the result overflows an int
>       * @since 1.8
>       */
>      public static int addExact(int x, int y) {
>          int r = x + y;
>          // HD 2-12 Overflow iff both arguments
>          // have the opposite sign of the result
>          if (((x ^ r) & (y ^ r)) < 0) {
>              throw new ArithmeticException("integer overflow");
>          }
>          return r;
>      }
> 
> HD 2-12 probably means Handbook of ... (who knows?)
> chapter 2 section 12.

https://en.wikipedia.org/wiki/Hacker's_Delight

... would be my guess.

-- 
esosman@comcast-dot-net.invalid
Eleven hundred eight days to go.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Can Java 8 do exact arithmetic as in C# bursejan@gmail.com - 2018-01-08 04:17 -0800
  Re: Can Java 8 do exact arithmetic as in C# j4n bur53 <janburse@fastmail.fm> - 2018-01-08 13:21 +0100
    Re: Can Java 8 do exact arithmetic as in C# Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-01-08 08:42 -0500
      Re: Can Java 8 do exact arithmetic as in C# j4n bur53 <janburse@fastmail.fm> - 2018-01-08 21:11 +0100
        Re: Can Java 8 do exact arithmetic as in C# bursejan@gmail.com - 2018-01-08 18:08 -0800
          Re: Can Java 8 do exact arithmetic as in C# bursejan@gmail.com - 2018-01-08 18:22 -0800
          Re: Can Java 8 do exact arithmetic as in C# v_borchert@despammed.com (Volker Borchert) - 2018-01-09 19:48 +0000
  Re: Can Java 8 do exact arithmetic as in C# Arne Vajhøj <arne@vajhoej.dk> - 2018-01-08 20:04 -0500
    Re: Can Java 8 do exact arithmetic as in C# bursejan@gmail.com - 2018-01-08 17:53 -0800

csiph-web