google / guava

Google core libraries for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Addition of Built-In Methods for Primitive Math operations

harishwar-babu opened this issue · comments

1. What are you trying to do?

  • I would like to add a new feature that focus on performing addition of 2 numbers irrespective of type (int,int) or (long,long) or (short,short). that too with the help of bitwise operators(^,&).
  • similarly for checking whether the number is even or odd. using & operator.
  • Note: The above 2 features will not work for double/floating point numbers It will work only for whole/natural numbers.
  • so, these are the above 2 features I would like to add to the Guava Math library.

2. What's the best code you can write to accomplish that without the new feature?

ExisitingFeature.txt

3. What would that same code look like if we added your feature?

NewFeature.txt

(Optional) What would the method signatures for your feature look like?

// for addition of two numbers.
public int add(int value1,int value2);
public long add(long value1,long value2);
public short add(short value1,short value2);

//for even number check
public int isEven(int value);
public long isEven(long value);
public short isEven(short value);

Concrete Use Cases

use-case.txt

Packages

com.google.common.math

Checklist

As discussed in #6982 (comment), the performance argument for the bitwise addition operations these is difficult to believe. For previous discussion of isEven, see #1229.