Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to fill a new DoubleVector with the fractional part of a division in Java Vector API?

Joao Valencio SilvaMar 31 2024 — edited Mar 31 2024

Hello, everyone,

I would like to know if it is possible to create a new DoubleVector, named RESULT, so that it is filled with the fracional part of the division of two other DoubleVectors, as shown bellow.

If so, I would like to ask your help to write a line of code to accomplish this task.

For example: 311708933 divided by 157 is 1985407.216560509554140127.

So, I would like to fill a new DoubleVector with the value 0.216560509554140127.

311708939 divided by 171 is 1822859.29239766081871345.

Fill the new DoubleVector with 0.29239766081871345..

And so on.

double[] v1 = {311708933, 311708939, 311708941, 311708951, 311708959, 311708981, 311708987, 311709037, 311709067, 311709071, 311709077, 311709103, 311709121, 311709137, 311709143, 311709157, 311709163, 311709169, 311709173, 311709191, 311709227, 311709283, 311709287, 311709337, 311709367, 311709379, 311709397, 311709407, 311709427, 311709439, 311709469, 311709473}; 
double[] v2 = {157, 171, 180, 183, 184, 289, 301, 306, 358, 449, 486, 539, 567, 605, 643, 655, 678, 680, 699, 711, 733, 750, 786, 799, 810, 827, 846, 873, 903, 923, 939, 981}; 
double[] result = new double[v1.length]; 
var species = DoubleVector.SPECIES_PREFERRED; 
for (int index = 0; index < v1.length; index += species.length()) { 
var V1 = DoubleVector.fromArray(species, v1, index); 
var V2 = DoubleVector.fromArray(species, v2, index); 
//-----> DoubleVector RESULT = get the fractional part of V1.div(V2);
RESULT.intoArray(result, index); 
}
for (int i = 0; i < result.length; i++) { 
System.out.println("result[" + i + "]: " + result[i]); 
}

Comments

Artan Hajdari Feb 11 2025

Can someone help me in this case please

1 - 1

Post Details

Added on Mar 31 2024
3 comments
176 views