Higher Precision Sums Than Double
Dec 31, 2014What is the simplest way to sum a huge number of double precision numbers so the sum has higher precision than double?
View RepliesWhat is the simplest way to sum a huge number of double precision numbers so the sum has higher precision than double?
View RepliesI 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]....
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] .....
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 RelatedI 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] ....
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 RelatedI'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
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');
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?
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?
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)
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?
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?
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] ....
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.
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
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]...
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...
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.
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
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
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//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.
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 ?
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] ....
What is the difference between float and double?
View Replies View Related