Questions tagged [double]

Double is a primitive data type used to store fractional numbers that holds a double-precision floating-point (often 64 bits).

In C and C++ double must be at least as large as float (another floating-point type), but its actual size can vary from system to system as it is implementation-defined. It is typically twice the size of float. Many systems store doubles in binary64, a format described in the IEEE 754 technical standard.

Java has a very strict definition for double, requiring it to be stored in binary64 (which is also called double-precision).

More information:

8301 questions
3
votes
4 answers

How to save double to file in python?

Let's say I need to save a matrix(each line corresponds one row) that could be loaded from fortran later. What method should I prefer? Is converting everything to string is the only one approach?
hahahaha
  • 31
  • 1
  • 4
3
votes
3 answers

Performant way to check java.lang.Double for equality

What is the most performant way to check double values for equality. I understand that double a = 0.00023d; double b = 0.00029d; boolean eq = (a == b); is slow. So I'm using double epsilon = 0.00000001d; eq = Math.abs(a - b) < epsilon; The…
mike
  • 4,929
  • 4
  • 40
  • 80
3
votes
2 answers

How to get similar result as if Thread.Sleep were supports double values?

Sometimes I need to sleep non integer amount of milliseconds, but can't find a way to do so. For example, if I want to sleep half of millisecond, I want to do this: Thread.Sleep(0.5); But can't, since Sleep supports integers only.
Kosmo零
  • 4,001
  • 9
  • 45
  • 88
3
votes
4 answers

c/c++: error of printing a double array returned by a function

I got a problem with the following code: #include using namespace std; double* FillArray(void) { double result[5]; for (int i = 0; i<5;i++){ result[i]=(double) i; } return result; // return the…
lxw
  • 91
  • 1
  • 6
3
votes
1 answer

In a DataGridTextColumn, on a column bound to a double value type, .05 gets converted to 5

The title more or less sums it up. If we have a completely clean WPF application, and add the following ViewModel: using System.Collections.ObjectModel; using System.ComponentModel; namespace WpfApplication10 { public sealed class ViewModel …
JMK
  • 27,273
  • 52
  • 163
  • 280
3
votes
5 answers

Converting double to float in C# giving wrong values

Question is real simple. I have a double which I want to convert to float. double doubleValue = 0.00000000000000011102230246251565; float floatValue = (float)doubleValue; Now when I do this. Float value just goes mad. Its value is "1.110223E-16" Do…
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
3
votes
4 answers

Getting the fractional part of a double value in integer without losing precision

i want to convert the fractional part of a double value with precision upto 4 digits into integer. but when i do it, i lose precision. Is there any way so that i can get the precise value? #include int main() { double number; double…
Atul Kumar Verma
  • 369
  • 3
  • 8
  • 23
3
votes
2 answers

Ordering operation to maximize double precision

I'm working on some tool that gets to compute numbers that can get close to 1e-25 in the worst cases, and compare them together, in Java. I'm obviously using double precision. I have read in another answer that I shouldn't expect more than 1e-15 to…
Matthieu
  • 2,736
  • 4
  • 57
  • 87
3
votes
1 answer

gcc - high execution time by copying a double into a integer

I am implementing a Filter and I need to optimised as much as possible the implementation. I have realised that there is an instruction that need a lot of cycles and I do not understand why: bool filters_apply(...) { short sSample; double…
Alicia R.
  • 53
  • 1
  • 5
3
votes
2 answers

Reading double values from a file and storing them in an array then display in listbox

these are the values from the textfile 1245.67 1189.55 1098.72 1456.88 2109.34 1987.55 1872.36 they are obviously decimals not sure what i'm missing but when i debug i get Input string was not in a correct format any help would be great thats…
user2451489
  • 31
  • 1
  • 4
3
votes
2 answers

java-Cast String Arraylist to double ArrayList

I have a String arraylist and i am going to convert it to a double arraylist. Is there any way except using loops like for,While to convert it? ArrayList S=new ArrayList(); S=FillTheList(); ArrayList D=new…
Sal-laS
  • 11,016
  • 25
  • 99
  • 169
3
votes
1 answer

Round a double number when printing to cout

I want to print only one digit after the decimal dot. So I write: double number1 = -0.049453; double number2 = -0.05000; cout.setf(ios::fixed,ios::floatfield); cout.precision(1); cout << number1 << endl; cout << number2 << endl; My output…
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
3
votes
1 answer

JSONObject removes decimal dot, if round number

Using a rest service, we are transfering values using JSON. At some point, we need to decide, wheter the incoming value was a long or a double. While Double d = 17.0; System.out.println("toString(): " + d.toString()); will result in toString():…
dognose
  • 20,360
  • 9
  • 61
  • 107
3
votes
5 answers

What is the minimum buffer size for sprintf with %g?

The problem is to statically allocate a buffer large enough to fit a printed double, formatted with %g at maximum precision. This seems like a simple enough task, bu I'm having trouble. The best I have come up with (assuming the number to be…
jkl
3
votes
3 answers

php foreach is outputting everything twice

everything works fine, but the output is being listed twice. so it echos out: 'output a' 'output a' 'output b' 'output b' 'output c' 'output c' and so on. when i do a mysql query in phpmyadmin, everything is only listed once. any ideas? what my code…
Ghost Echo
  • 1,997
  • 4
  • 31
  • 46