double

acos(double) gives different result on x64 and x32 Visual Studio

回眸只為那壹抹淺笑 提交于 2019-12-31 04:00:06
问题 acos(double) gives different result on x64 and x32 Visual Studio. printf("%.30g\n", double(acosl(0.49990774364240564))); printf("%.30g\n", acos(0.49990774364240564)); on x64: 1.0473040763868076 on x32: 1.0473040763868078 on linux4.4 x32 and x64 with sse enabled: 1.0473040763868078 is there a way to make VSx64 acos() give me 1.0473040763868078 as result? 回答1: TL:DR: this is normal and you can't reasonably change it. The 32-bit library may be using 80-bit FP values in x87 registers for its

add two double given wrong result

拈花ヽ惹草 提交于 2019-12-31 03:29:09
问题 I'm using the following piece of code and under some mysterious circumstances the result of the addition is not as it's supposed to be: double _west = 9.482935905456543; double _off = 0.00000093248155508263153; double _lon = _west + _off; // check for the expected result Debug.Assert(_lon == 9.4829368379380981); // sometimes i get 9.48293685913086 for _lon (which is wrong) I'm using some native DLLs within my application and i suspect that some DLL is responsible for this 'miscalculation',

Finding floating points in a large string

倾然丶 夕夏残阳落幕 提交于 2019-12-31 03:24:26
问题 I have a large string that has a series of floating points in string. A typical string would have Item X $4.50 Description of item \r\n\r\n Item Z $4.75... There is really no rhyme or reason for the text. I have the lowest already and I need to find all the values in the string. So if it was 10.00 it would find every value that is 10.05 or less. I would assume that some sort of regex would involved to find the values and then I could put them in an array then sort them. So it would be

Finding floating points in a large string

前提是你 提交于 2019-12-31 03:24:07
问题 I have a large string that has a series of floating points in string. A typical string would have Item X $4.50 Description of item \r\n\r\n Item Z $4.75... There is really no rhyme or reason for the text. I have the lowest already and I need to find all the values in the string. So if it was 10.00 it would find every value that is 10.05 or less. I would assume that some sort of regex would involved to find the values and then I could put them in an array then sort them. So it would be

How to sort an ArrayList with object using stream().sorted()

断了今生、忘了曾经 提交于 2019-12-30 09:56:47
问题 I am having real trouble with using stream and sorted to sort my ArrayList and hope someone can help out. The code uses Croatian words, but I don't think that will be a problem for someone who understands what I mean. This is the ArrayList ArrayList<Publikacija> listaPublikacija = new ArrayList<>(); listaPublikacija.add(prvaKnjiga); listaPublikacija.add(drugaKnjiga); listaPublikacija.add(prviCasopis); listaPublikacija.add(drugiCasopis); In my assignment I am supposed to sort these objects

Is Double.MIN_VALUE is greater than zero in Java?

≯℡__Kan透↙ 提交于 2019-12-30 05:45:26
问题 I found a bug in my code which boiled down to comparing Double(0.0) with Double.MIN_VALUE . Essentially, the following returns false: System.out.println(0.0 > Double.MIN_VALUE); How is this possible? 回答1: According to the javadoc for Double.MIN_VALUE, MIN_VALUE is: A constant holding the smallest positive nonzero value of type double So Double.MIN_VALUE is not negative, it's the positive value that's as close as a Double can get to zero (without being zero). 回答2: Double.MIN_VALUE is the

toString() method within System.out.println() a double call?

强颜欢笑 提交于 2019-12-30 04:06:08
问题 A professor of mine once said that the following code should never be done: System.out.println(object.toString()); He said (and I believe cited "Effective Java") it causes a double call. Since the print statement calls the toString method of an object, it would be less efficient to have the toString method called twice. The preferred method would be to just use: System.out.println(object); Obviously this way looks better in code and would save time. I will always do it like this no matter

Show decimal of a double only when needed

人走茶凉 提交于 2019-12-30 02:34:56
问题 I got this problem with double (decimals). When a double = 1.234567 Then I use String.format("%.3f", myString); So the result is 1.234 But when my double is 10 The result will be 10,000 I want this to be 10 Is their a way to say that he only needs to show the decimals when it is "usefull"? I saw some posts about this, but that was php or c#, couldn't find something for android/java about this (maybe I don't look good). Hope you guys can help me out with this. Edit, for now I use something

How to get the Power of some Integer in Swift language?

眉间皱痕 提交于 2019-12-29 10:34:44
问题 I'm learning swift recently, but I have a basic problem that can't find an answer I want to get something like var a:Int = 3 var b:Int = 3 println( pow(a,b) ) // 27 but the pow function can work with double number only, it doesn't work with integer, and I can't even cast the int to double by something like Double(a) or a.double()... Why it doesn't supply the power of integer? it will definitely return an integer without ambiguity ! and Why I can't cast a integer to a double? it just change 3

How to get the Power of some Integer in Swift language?

落爺英雄遲暮 提交于 2019-12-29 10:34:38
问题 I'm learning swift recently, but I have a basic problem that can't find an answer I want to get something like var a:Int = 3 var b:Int = 3 println( pow(a,b) ) // 27 but the pow function can work with double number only, it doesn't work with integer, and I can't even cast the int to double by something like Double(a) or a.double()... Why it doesn't supply the power of integer? it will definitely return an integer without ambiguity ! and Why I can't cast a integer to a double? it just change 3