floating-point

Floating Point Div/Mul > 30 times slower than Add/Sub?

I recently read this post: http://stackoverflow.com/questions/2550281/floating-point-vs-integer-calculations-on-modern-hardware and was curious as to the performance of my own processor on this quasi-benchmark, so I put together two versions of the code, one in C# and one in C++ (Visual Studio 2010 Express) and compiled them both with op...

Cast to int vs floor

Is there any difference between these: float foo1 = (int)(bar / 3.0); float foo2 = floor(bar / 3.0); As I understand both cases have the same result. Is there any difference in the compiled code? Note: updated fabs() to floor() as that was the real question ...

C++ arithmetic operations in floating point

Is there a way in C++ to have it evaluate each floating point operation as a double even if the arguments are int? I have a program and numerous places I have code such as 1/2, 5/6. In these cases C++ casts the result to an int, that screws up the whole calculation. From the perspective of financial computations, are there other librarie...

Decimal precision of floats

equivalent to log10(2^24) ≈ 7.225 decimal digits Wikipedia Precision: 7 digits MSDN 6 std::numeric_limits<float>::digits10 Why numeric_limits return 6 here? Both Wikipedia and MSDN report that floats have 7 decimal digits of precision. ...

How to display rationals as long lists of digits in Lisp?

I'm just starting to learn Lisp and was wondering how to display a rational as a decimal number with lots of digits. If I use (float x), where x is a rational then it displays about 8 digits or so. But I want to display hundreds of digits. ...

My variance function in C# does not return accurate value

The source data : static double[] felix = new double[] { 0.003027523, 0.002012256, -0.001369238, -0.001737660, -0.001647287, 0.000275154, 0.002017238, 0.001372621, 0.000274148, -0.000913576, 0.001920263, 0.001186456, -0.000364631, 0.000638337, 0.000182266, -0.001275626, -0.000821093, 0.001186998, -0.000455996, -0.0...

What's the difference between hard and soft floating point numbers?

When I compile C code with my cross toolchain, the linker prints pages of warnings saying that my executable uses hard floats but my libc uses soft floats. What's the difference? ...

Perl modulo operator question

Why does the first example print a wrong result ? perl -le 'print $x = 100*1.15 % 5' 4 perl -le 'print $x = 1000*1.15 % 5' 0 ...

C++/CLI: SIGFPE, _control87, _fpreset, porting ancient unmanaged Watcom C app to .NET

I have a several-thousand-line application that relies on SIGFPE (handled by a function pointer passed to signal()) to change state and have the code run correctly when certain floating point conditions happen. However, under C++/CLI in managed-mode, _control87 generates a System.ArithmeticException executing in a static lib written in ...

Javascript: Comparing two float values

I have this JavaScript function: Contrl.prototype.EvaluateStatement = function(acVal, cfVal) { var cv = parseFloat(cfVal).toFixed(2); var av = parseFloat(acVal).toFixed(2); if( av < cv) // do some thing } When i compare float numbers av=7.00 and cv=12.00 the result of 7.00<12.00 is false! Any ideas why? ...

Why does this loop never end?

Possible Duplicate: problem in comparing double values in C# I've read it elsewhere, but really forget the answer so I ask here again. This loop seems never end regardless you code it in any language (I test it in C#, C++, Java...): double d = 2.0; while(d != 0.0){ d = d - 0.2; } ...

C/C++ optimization: negate doubles fast

I need to negate very large number of doubles quickly. If bit_generator generates 0, then the sign must be changed. If bit_generator generates 1, then nothing happens. The loop is run many times over and bit_generator is extremely fast. On my platform case 2 is noticeably faster than case 1. Looks like my CPU doesn't like branching. Is ...

strange assembler... could this be the cause of my apps crash?

I have a program in native C++ under windows that uses a VB6 DLL. The C++ app crashes with a "Floating Point In-exact Result" error when using that DLL, for a certain action. When I go into debug and do view assembler I get this line: 75A0FB7C je 759E8797 When you hover over the right most address it shows a tooltip with ...

php convert floating point to long (convert to string to pass to a xml function)

Hi, PHP converts a large number to floating point which I need in "long" format to pass to a soap xml api. ((round(time()/(60*15))*60*15)+(30*60))*1000 This gives the result: 1.28E+12 Whereas, what I need is: "1280495700000" in order to pass to the api ...

Why does the use of integer variables throw an exception?

Hi, I have come across with the following two codes. Why does it not throw an exception for floating point where as in other case it will throw a runtime exception. class FloatingPoint { public static void main(String [] args) { float a=1000f; float b=a/0; System.out.println("b=" +b); } ...

Floating point problem in SQL Server 2005

The code below is used to calculate the miles between two cities. In this case, it's for the distance from Yarmouth, ME to Yarmouth, ME - obviously zero - meaning that results for cities within X miles of Yarmouth should include Yarmouth itself. The problem is that the latitude and longitude for Yarmouth seem to be causing some kind of ...

Floating point C++ compiler options | preventing a/b -> a* (1/b)

I'm writing realtime numeric software, in C++, currently compiling it with Visual-C++ 2008. Now using 'fast' floating point model (/fp:fast), various optimizations, most of them useful my case, but specifically: a/b -> a*(1/b) Division by multiplicative inverse is too numerically unstable for a-lot of my calculations. (see: Microsoft...

Double vs. BigDecimal?

I have to calculate some floating point variables and my colleague suggest me to use BigDecimal instead of double since it will be more precise. But I want to know what it is and how to make most out of BigDecimal? Thanks! ...

Issues with checking the equality of two doubles in .NET -- what's wrong with this method?

Hi, So I'm just going to dive into this issue... I've got a heavily used web application that, for the first time in 2 years, failed doing an equality check on two doubles using the equality function a colleague said he'd also been using for years. The goal of the function I'm about to paste in here is to compare two double values to...

Serialize double and float with C

How can I serialize doubles and floats in C? I have the following code for serializing shorts, ints, and chars. unsigned char * serialize_char(unsigned char *buffer, char value) { buffer[0] = value; return buffer + 1; } unsigned char * serialize_int(unsigned char *buffer, int value) { buffer[0] = value >> 24; buffer[1]...