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


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

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

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Can Java 8 do exact arithmetic as in C#
Date 2018-01-08 20:04 -0500
Organization Aioe.org NNTP Server
Message-ID <p314fm$1lag$1@gioia.aioe.org> (permalink)
References <0ef8b3c0-e45c-4624-a8b8-2bdc67135380@googlegroups.com>

Show all headers | View raw


On 1/8/2018 7:17 AM, bursejan@gmail.com wrote:
> Java 8 has a nice feature, maybe this
> isn't known very well. But there are
> 
> a couple of new operations in Math:
> 
>      /**
>       * 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);
> 
>      /**
>       * Returns the sum of its arguments,
>       * throwing an exception if the result overflows a {@code long}.
>       *
>       * @param x the first value
>       * @param y the second value
>       * @return the result
>       * @throws ArithmeticException if the result overflows a long
>       * @since 1.8
>       */
>      public static long addExact(long x, long y);

Nice.

But probably of limited value.

The programmers calling these methods do so because
they are aware of the risk of overflow.

If these methods did not exist they would still be
aware and (hopefully) do something else to handle
the problem.

The problem is the programmers not aware of the
risk of overflow.

And these methods does not help them.

Arne

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