Higher Precision Sums Than Double

Dec 31, 2014

What is the simplest way to sum a huge number of double precision numbers so the sum has higher precision than double?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Filling A Rectangle With Double Precision

Mar 4, 2014

I have run into a bit of a head scratcher, at least to me. I am building multiple rectangles using double precision. I had to switch from int to double due to another issue that requires decimal places. Now, my fillRect (last line in the code section I posted) is causing an error as it only wants to work with int.

public void draw(Graphics2D g2) {
// check that sizes are above 0
if ((rectWidth <= 0) || (rectHeight <= 0))

[Code]....

View Replies View Related

Program To Approximate Integral Of Function Sin Using Riemann Sums

Oct 3, 2014

I am working on this program to approximate the integral of the function sin(x)/x using Riemann sums (left hand). It is close, but whenever I try to check it in the web grader some of my results are way off. Here is my code.

public class Integrate {
public static void main(String[] args) {
if (args.length != 3) {
System.out.println("Error: must enter a, b, n");
System.exit(1);

[Code] .....

View Replies View Related

Write Unit Tests When Some Other Classes Are Involved And Abstraction Is Much Higher?

Mar 5, 2015

I have two classes Person and Group. Group object is suppose to contain many Persons, How can I write unit tests when some other classes are involved and abstraction is much higher?

View Replies View Related

Sorting Rows (lower To Higher Number) From A Group Of Integers

Apr 24, 2015

I have to organize the rows from the lower to the higher number, the problem is, what I have only organizes the first 3 rows even If I insert 3,4,5...or 10 rows.

int arg[][] = {
{26, 39, 3, 13},
{22, 97, 17, 123},
{46, 19, 63, 123},
{1, 37, 90, 32},
{17, 37, 90, 32}};

for (int i = arg[0].length - 1; i >= 0; i--) {
for (int j = 0; j < i ; j++) {
for (int k = 0; k < i ; k++) {
if (arg[k][j] > arg[k][j + 1]) {
int temp = arg[k][j];

[Code] ....

View Replies View Related

Compare Two Random Numbers And Declare Player With Higher Value The Winner

Apr 19, 2015

How to start and structure my program because i am fairly new to the program but want to try to make a game. My idea of the game is it generates random numbers between 1-100 for two people and the program compares the two random numbers and declares the player with the higher value the winner like the card game war. Then it would give you an option to try again.

View Replies View Related

Error - Possible Loss Of Precision

Feb 10, 2015

I'm stuck trying to figure out why this isn't compiling.

Bumper.java:87: error: possible loss of precision
myX = (Math.random()* (rightEdge-myXWidth) + myXWidth / 2);
^
required: int
found: double
Bumper.java:88: error: possible loss of precision
myY = (Math.random()* (bottomEdge-myYWidth) + myYWidth / 2);
^
required: int
found: double

View Replies View Related

Changing Precision Of A Float?

Jan 26, 2014

Ok, so in my quest to achive perfect ray casting and line/plane intersection, what I believe to be my last problem is precision of a float. I need some precision (0.000) but I am dealing with the difference of (-1.000000000) and (-1.000000002), where the second number would be completely off. I looked at DecimalFormat, but that just puts it into a string, I need actual loss of precision.

Java Code:

DecimalFormat form = new DecimalFormat("0.00");
String newX = form.format(x);
String newY = form.format(y);
String newZ = form.format(z);
x = Float.parseFloat(newX);
y = Float.parseFloat(newY);
z = Float.parseFloat(newZ); mh_sh_highlight_all('java');

View Replies View Related

Array Index - Possible Loss Of Precision

Feb 5, 2015

public class Access
{
public static void main(String args[])
{
long a=2;
int j[]=new int[a];
}
}

Code shows error as "possible loss of precision" as am working with long type.but need to have my array size as 10^10 or some other logic?

View Replies View Related

Determine All Of Perfect Squares Between 1 And 100 - Precision Error?

Mar 26, 2015

I am teaching myself Java and am trying to write a function that will determine all of the perfect squares between 1 and 100 but am running into a problem...

Here's my code:

package sqrroot;

public class SqrRoot {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double sroot, rerr;
int count = 0;
for(double num = 1.0; num <= 100.0; num++){

[Code] ....

and here is the output:

run:
0.0
1.0 is a perfect square.
0.0
4.0 is a perfect square.

[Code] ....

There are 49 perfect squares between 1 and 100.
BUILD SUCCESSFUL (total time: 6 seconds)

Which is clearly wrong. Is there something wrong with my code or is this due to inherent imprecision in the double type or the Math.sqrt function?

View Replies View Related

Precision And Recall Testing For Search Engines

May 14, 2014

I have code for precision and recall testing for search engines. I am trying to run it in Newbeans 8.0, but I am getting the common error in UnsupportedOperationException

I have tried making files and directories as the given in the code file. I am attaching the two files here.

Attached File(s)

 PrecisionRecall.rtf (1.79K)
 FSDirectory.rtf (687bytes)
error file-result.rtf (506bytes)

View Replies View Related

Floating Point Precision - Output With Two Decimal Places?

Jan 27, 2015

Consider this small program and output.

public class Floating{
public static void main( String[] args ){
System.out.println( 2.80 - 1.75 );
}
}

The output is 1.0499999999999998. Why not 1.05?

View Replies View Related

Extract Higher-order Bits Of Random Number In Order To Get Longer Period

Mar 1, 2014

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

View Replies View Related

Calculate Person Calories Burned Per Minute - Possible Loss Of Precision Error

Feb 2, 2015

I was asked to write code to calculate a person's calories burned/min. This is what I got. The problem is I keep getting an error.

--------------------Configuration: <Default>--------------------
C:Program FilesJavajdk1.7.0_72CaloriesBurned.java:22: error: possible loss of precision
caloriesBurnedPerMinute = 0.0175 * METS * weightInKg;
^
required: int
found: double
1 error

Loss of precision? What does that mean? Do I have to change weightInKg into some other number type?

import java.util.Scanner;
public class CaloriesBurned
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int runningHours, basketballHours, sleepingHours, METS, caloriesBurnedPerMinute;

[Code] ....

View Replies View Related

Getting Int Type Cast To Lower Precision Char Type In Parasoft JTEST

Mar 11, 2014

Below code I am using to typecast int to char.

char escapeValue = (char)0;
char cha = (char) 10;
escapeValue = (char)(escapeValue * cha); // Here am getting the above error.

I have 38 similar issues in my workspace.

View Replies View Related

Conversion From Double To Int?

Nov 30, 2014

I'm having some trouble with a code I am writing for class. I had an 2 errors like this before this one and fixed it by changing int avgRe, avgMiles =0; to double. Now I am getting this error and am stuck on what I need to change. Here is the code:

import java.io.*;
import java.util.*;
import java.text.*;
 public class Reimbursement_3_09 {
 static Toolkit tools = new Toolkit();
 public static void main (String [] args) throws Exception {
 
[Code] ....

This is my error:

[code=Java]
Reimbursement_3_09.java:33: error: incompatible types: possible lossy conversion from double to int
summary (outFile, totalAmount, ctrMiles, ctrMilesgt0, avgRe, avgMiles);
^
Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error

View Replies View Related

How To Compare Double

Jun 17, 2014

how can i compare two double values is this correct

Java Code:

public boolean isEqualToD(double s_src, double s_compareTo)
{
boolean flag = false;
try
{
if(s_src == s_compareTo)
{
flag = true;

[code]...

View Replies View Related

Array With Double And Int

Apr 11, 2015

Okey so i want to make an array like this

km = miles
10 6.214
15 9.321
20 12.428

and so on its a converter between km and miles and i have no clue how to do this...

View Replies View Related

Percentage Of A Double

Feb 14, 2014

Java Code:

double Compact=30.50;
double Full=40.50;
double discount=.07;
double FullDiscount= 37.67;
double CompactDiscount= 28.37; mh_sh_highlight_all('java');

My question is how do I configure this so that when / if I need to change the discount value, it automatically adjusts the % discount off of the Full or Compact?

All I can get to work is simply hardcoding it and assigning the discount value, i'm probably just messing up the syntax.

View Replies View Related

Cannot Cast From Object To Double

Nov 9, 2014

ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("js");
String expres = calc.getText().toString();
calc.setText(expres);
try {
calc.setText(((double)engine.eval(expres)) + "");
} catch (Exception e) {
}

This line: calc.setText(((double)engine.eval(expres)) + "");

*The error message for this line: Cannot cast from object to Double

View Replies View Related

Double To Hex String Conversion

May 8, 2014

I am trying to convert the double 4270571936.0000000000d to a hex string using Double.toHexString() and the answer I'm getting is 0x1.fd17834p31, what does p stands for?

The answer I'm expecting to get is 0x41efd17834000000 so not sure why it won't give me the correct answer?

The following floating point Double to hex calculator shows the write answer right Floating Point to Hex Converter

View Replies View Related

JSF :: How To Confirm A Field Only Contain Double

Jun 30, 2014

I have a jsf page.i need to confirm one filed only contain double value.how to validate this? I checked and found there is a validateDoubleRange,but its not suitable for this.

View Replies View Related

Cannot Convert From String To Double

Oct 4, 2014

//Students Full Name
firstName = JOptionPane.showInputDialog("Enter student " +
"first name.");
lastName = JOptionPane.showInputDialog("Enter student " +
"last name.");
// Get test grade (numbers)
[b]test1 = JOptionPane.showInputDialog("Enter test1 grade")[/b];

The line in bold is where that error comes up. I know it something simple but I can't remember. I declared both firstName and lastName as Strings and then the test1 I declared as double. I had a similar error in a previous assignment where I had a integer(age) input and then i had an output statement asking for a name all I needed to do was put keyboard.nextLine(); after my age input and I was fine.

View Replies View Related

Conversion Char To Double Value

Mar 31, 2015

I need to understand the java Conversion.

I have a char[] containing ASCII characters that need to be converted into int value and double value.

The int value are always stored in 1 char size like 'j'. I extracted it succesffully by converting the char in a ascii bytearray and then used: Integer.parseInt(sb.toString().replace("0x", ""), 16);

How can I get the Value as double when i used the char[] with size 2 or 4 ?

Example : final char[] charValue = { 'u', ' ', '}','+' }; what is the associate Double value ?

Example : final char[] charValue = { 'T', ' ' }; what is the associate Double value ?

Example : final char[] charValue = { 'T', ' ' }; what is the associate int value ?

View Replies View Related

Typing Double Name In The String

Oct 26, 2014

I am making a program where the user types in how many students, the student name and the student result. My problem is typing in a dobule name for instance: Tom Tom.

I have tried both:

String name = input.Next(); -> Only works with one name.
and
String name = input.nextLine(); -> Skips right trough and ask me to type result again.

Here is my code:

Java Code:

import java.util.Scanner;
public class c5e8 {
public static void main(String[]args){
Scanner input = new Scanner (System.in);
int highestResult = 0;
String highestName = " ";

[Code] ....

View Replies View Related

What Is Difference Between Float And Double

Jan 31, 2011

What is the difference between float and double?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved