double

Dealing with small numbers and accuracy

随声附和 提交于 2019-12-08 01:28:08
问题 I have a program where I deal with a lot of very small numbers (towards the lower end of the Double limits). During the execution of my application, some of these numbers progressively get smaller meaning their "estimation" is less accurate. My solution at the moment is scaling them up before I do any calculations and then scaling them back down again? ...but it's got me thinking, am I actually gaining any more "accuracy" by doing this? Thoughts? 回答1: Are your numbers really in the region

Java Double variables have strange values [duplicate]

孤街浪徒 提交于 2019-12-08 00:55:25
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Floating point arithmetic not producing exact results in Java I was doing this simple division but I get a very strange output: double a = 60/(1.2-1.1); a => 600.0000000000008 When it should be 600. thanks in advance 回答1: In IEEE-754 binary double, we need to consider 1.1 and 1.2 in the binary representation: 1.2 = 0b1.001100110011001100110011001100110011001100110011001100110011... 1.1 = 0b1

java double calculation

为君一笑 提交于 2019-12-08 00:54:01
问题 I understand that computer can not represent non-integral numbers precisely. so when I add 2 doubles in java for example: 724.64d + 1000d the console print out 1724.6399999999999 but why for 724.64d + 100d and 724.64d + 10000d the console print out 824.64 and 10724.64 separately? is there a way to know at what condition when I add the 2 doubles, the sum is the exact number ? The reason why I ask is because that our old program use double to do calculation. and use double comparison to

Formatting Double into a String in iReport

落爺英雄遲暮 提交于 2019-12-07 23:49:19
问题 I'm doing a report, that I need to join 4 variables in one. If I treat the variables separately I can format them with no problem. But when I merge them into a String, the double value comes as 0.0 instead of 0.00 How can I make it comes as the original, 0.00? The code right now looks like this: $F{someDoubleField} + "a string" + $F{anotherDoubleField} + "another string" It prints: 0.0 a string 0.0 another string instead of: 0.00 a string 0.00 another string Remember that iReport uses Java,

Reading double from binary file (byte order?)

江枫思渺然 提交于 2019-12-07 20:12:39
问题 I have a binary file, and I want to read a double from it. In hex representation, I have these 8 bytes in a file (and then some more after that): 40 28 25 c8 9b 77 27 c9 40 28 98 8a 8b 80 2b d5 40 ... This should correspond to a double value of around 10 (based on what that entry means). I have used #include<stdio.h> #include<assert.h> int main(int argc, char ** argv) { FILE * f = fopen(argv[1], "rb"); assert(f != NULL); double a; fread(&a, sizeof(a), 1, f); printf("value: %f\n", a); }

How does DoubleUtil.DoubleToInt(double val) work?

我的梦境 提交于 2019-12-07 19:18:22
问题 The MS.Internal.DoubleUtil -Class contains the function public static int DoubleToInt(double val) { return (0 < val) ? (int)(val + 0.5) : (int)(val - 0.5); } I wonder why this 'converts' val to an Integer? 回答1: The cast from double to int always takes the floor, so adding .5 (or subtracting .5 if it is negative) means 1.6 returns 2, while 1.4 would return 1. 回答2: For numbers > 0 it adds 0.5 and truncates. For numbers < 0 it subtracts 0.5 and truncates. The (int) cast in fact truncates, so

Where is the source code for isnan?

久未见 提交于 2019-12-07 18:07:01
问题 Because of the layers of standards, the include files for c++ are a rats nest. I was trying to figure out what __isnan actually calls, and couldn't find anywhere with an actual definition. So I just compiled with -S to see the assembly, and if I write: #include <ieee754.h> void f(double x) { if (__isinf(x) ... if (__isnan(x)) ... } Both of these routines are called. I would like to see the actual definition, and possibly refactor things like this to be inline, since it should be just a bit

Conversion of entire array from int to double in order to do some aritmetic operations

不羁的心 提交于 2019-12-07 18:04:27
I have this bit of code: var arrayIntegers : [Int] = [] arrayIntegers += 0...33 var arrayDecimal : [Int] = [] arrayDecimal += 0...999 The problem is I can´t convert the values of both arrays to Double. What I want to do is to get a new array (called arrayDoubleComposed) with composite values, taking a value of arrayIntegers as the integer part and then taking another value of arrayDecimal as the floating part. When I try to typecast this: var arrayDoubleComposed : [Double] = [] arrayDoubleComposed = Double (arrayIntegers[] + (arrayDecimal[])/1000) I´ve got an error. The same if I suppress the

How to check for null value for a double which is taken from a database

亡梦爱人 提交于 2019-12-07 17:31:32
问题 I am extracting values from a database. I am extracting a double value from a database using ResultSet rs = ....; while(...){ rs.getDouble("num"); } How do I check if the value of rs.getDouble("num") is a null. Since the value is stored as a (MySQL) double and I want to store it in my JVM as a double, I can't simply use !=null. What is the easiest way. Would converting the value to a Double() and then doing .equals(null) be the easiest/best (in your opinion) way? 回答1: Test rs.wasNull() after

How many bits of precision for a double between -1.0 and 1.0?

孤街浪徒 提交于 2019-12-07 15:22:33
问题 In some of the audio libraries I've been looking at, a sample of audio is often represented as a double or a float with a range of -1.0 to 1.0. In some cases, this easily allows analysis and synthesis code to abstract what the underlying datatype might actually be (signed long int, unsigned char, etc). Assuming IEEE 754, we have non-uniform density. As the number approaches zero, the density increases. This means that we have less precision for numbers approaching -1 and 1. This non-uniform