double

Java Text Box Validation Using Double.parseDouble()

Hi. I have a Swing JTextBox that basically will hold a double. I find that using: Double.parseDouble(this.myTB.getText()); will throw an exception (and thus program is terminated) whenever Double.parseDouble() gets invalid input. My question: is there an easy way to NOT throw an exception, and instead return an integer (-1) s...

Python: Unpack from hex to double

Python: Unpack from hex to double This is the value value = ['\x7f', '\x15', '\xb7', '\xdb', '5', '\x03', '\xc0', '@'] I tried unpack('d', value) but he needs a string for unpacking. It is a list now. But when I change it to a string, the length will change from 8 to 58. But a double needs a value of the length 8. ...

Calling C DLL from Visual Basic 6: Double data type not working

I'm passing a simple user-defined type (UDT) from Visual Basic 6 to a C DLL. It works fine, except for the double data type, which shows up as 0. C DLL: #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <stdio.h> typedef struct _UserDefinedType { signed int Integer; unsigned char Byte; float Float...

jquery sortable/draggable double event firing

I have some drag & drop code which works fine as it is. Just have a little query. I've noticed that if I add an alert within the drop function for debugging purposes (eg. alert(draggedItem.text());) it fires the alert twice when I drop something into the draggable area. I've read in another post that using droppable & sortable together c...

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

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. Wh...

Convert double into hex in C#

I have this value: double headingAngle = 135.34375; I would like to convert it to HEX and print the HEX to the console. I have already converted a string and int into their respective HEX values, but a double seems to be much more tricky. Can someone point me in the right direction? ...

Is there a nice Java object to hold a 2D grid of doubles?

Is there a data type that simply holds a 2D grid of doubles? Preferably in the JDK but I'm happy to use an open source 3rd party library like apache commons etc. I'm looking for a class, and/or complimentary helper classes, that allow methods like these: Grid g = new DoubleGrid(100, 100); double min = g.getMinValue(); double someCell...

C++ / C# differences with float and double

We are converting a C++ math library to C#. The library mixes the use of floats and doubles (casting between them sometimes) and we are trying to do the same, in order to get the exact same results in C# that we had in C++ but it is proving to be very difficult if not impossible. I think the problem is one or more of the following, but ...

Why this xUnit test fails?

Assert.Equal(1000000.0, table.Convert("g", "mcg", 1.0)); // Pass Assert.Equal(2000000.0, table.Convert("g", "mcg", 2.0)); // Pass Assert.Equal(3200000.0, table.Convert("g", "mcg", 3.2)); // Fail // The failing one is equal to doing the following calculation, which fails also: Assert.Equal(3200000.0, 3.2 * 1.0 / (1.0 / 1000000.0)); // Fa...

C - floor of double moduls integer

I need to do the following equation floor(e%100000) where e is a double. I know mod only accepts int values, how do I go about achieving this same result? Thanks ...

parse non-negative doubles

Hi! I need function that will take string and integer that indicates position of non-negative double or integer and return Number or null. If there is '+' return null. Examples 2.1 , 0 -> 2.1 +2.1 , 0 -> null -1 , 0 -> null -1.2 , 1 -> 1.2 qwa56sdf , 3 -> 56 What is the most elegant way to do this? Thanks. upd I ...

How can I get the Double.toString() behaviour AND thousands separator?

I want to add the thousands separator to a variable of type double. I have tried using String.format("%,f", x); and similar, but it seems to have a fixed number of decimal places, unlike Double.toString(). For example, with the value 1234.5: Double.toString(): 1234.5 String.format(): 1.234,500000 Desired: 1.234,5 ...

Difference between a double in c# and objective-c when converting to string

I am in the process of migrating the awesome c# geocode framework http://code.google.com/p/geocoordconversion/ to objective-c however I've noticed a subtle difference. There is a line in the code which does the following: int retVal = Math.Abs(allAfterDecimal).ToString().Trim('0').Length - 1; Now I have written matching test scrip...

Pass application via argv in Applescript

I would like to pass the name of an application to an applescript and then perform some actions on it in the script. I've tried the following: set app_name to item 1 of argv tell application app_name to ... This doesn't work. I've tried set app_name to quoted form of item 1 of argv which seems to append single quotes, (doesn't work...

C# double precision problem

Hi all! Imagine that a - b < c (a, b, c are C# doubles). Is it guaranteed that a < b + c? Thanks! EDIT Let's say that the arithmetical overflow doesn't occur unlike the following example: double a = 1L << 53; double b = 1; double c = a; Console.WriteLine(a - b < c); // Prints True Console.WriteLine(a < b + c); // Prints False Imag...

Problem with Double and division

Possible Duplicates: Ints and Doubles doing division 1/252 = 0 in c#? Hi, Maybe because it's Friday, but I cannot understand this: (Double)1/2 = 0.5 (Double)1/(Double)2 = 0.5 (Double)((Double)1/(Double)2) = 0.5 (Double)(1/2) = 0.0 Why the last operation is 0? :S Kind regards. ...

C++ String to Double parsing with exceptions?

In java, if I wanted to create some application which could receive both doubles and strings as appropriate input, I would probably do the following: String input = getInput();// try { double foo = Double.valueOf(input); //Do stuff with foo here } catch (NumberFormatException e) { //Do other validation with input } How...

64 bit floats compiled with 32 bit compiler on 64 bit OS.

I hope this has not been covered before, but if i compile a 32 bit program in c++ that uses 64 bit floating point numbers (double), and run it on a 64 bit OS, will it still take as many clock cycles to move the 64 bit float to the cpu and back to ram as it would on a 32bit OS because its compiled for 32 bit. Or would it take less clock c...

Integer vs double arithmetic performance?

Hi, i'm writing a C# class to perform 2D separable convolution using integers to obtain better performance than double counterpart. The problem is that i don't obtain a real performance gain. This is the X filter code (it is valid both for int and double cases): foreach (pixel) { int value = 0; for (int k = 0; k < filterO...

Is reading a double not thread-safe?

Update: I just stumbled upon this in Eric Lippert's answer to another question (he is quoting the spec): Reads and writes of other types, including long, ulong, double, and decimal, as well as user-defined types, are not guaranteed to be atomic. OK, so reading a double is not atomic. This means the value could get modified ...