precision

ArithmeticException thrown during BigDecimal.divide

I thought java.math.BigDecimal is supposed to be The Answer to the need of performing infinite precision arithmetic with decimal numbers. Consider the following snippet: import java.math.BigDecimal; //... final BigDecimal one = BigDecimal.ONE; final BigDecimal three = BigDecimal.valueOf(3); final BigDecimal third = one.divide(three); ...

Loss of precision - int -> float or double

I have an exam question i am revising for and the question is for 4 marks "In java we can assign a int to a double or a float". Will this ever loose infromation and why? I have put that because ints are normally of fixed length or size - the precision for sotring data is finite, where storing information in floating point can be infin...

Double precision values

Just a day before I participated in the qualification round of Google Code Jam. This is my first experience of such an online coding contest. It was really fun. There were three problems given of which i was able to solve two. But on one of the problems I was asked to work with values that are really huge. I am a Java guy and I thought ...

"possible loss of precision" is Java going crazy or I'm missing something?

I'm getting a "loss of precision" error when there should be none, AFAIK. this is an instance variable: byte move=0; this happens in a method of this class: this.move=(this.move<<4)|(byte)(Guy.moven.indexOf("left")&0xF); move is a byte, move is still a byte, and the rest is being cast to a byte. I get this error: [javac] /Users/...

x86-64 long double precision

hello. What is the actual precision of long double on Intel 64-bit platforms? is it 80 bits padded to 128 or actual 128 bit? if former, besides going gmp, is there another option to achieve true 128 precision? ...

How to calculate a operation's time in micro second precision

I want to calculate performance of a function in micro second precision on Windows platform. Now Windows itself has milisecond granuality, so how can I achieve this. I tried following sample, but not getting correct results. LARGE_INTEGER ticksPerSecond = {0}; LARGE_INTEGER tick_1 = {0}; LARGE_INTEGER tick_2 = {0}; double uSec = 10000...

Is long long in C++ known to be very nasty in terms of precision?

The Given Problem: Given a theater with n rows, m seats, and a list of seats that are reserved. Given these values, determine how many ways two friends can sit together in the same row. So, if the theater was a size of 2x3 and the very first seat in the first row was reserved, there would be 3 different seatings that these two guys can...

SQL Server cast fails with arithmetic overflow

According to the entry for decimal and numeric data types in SQL Server 2008 Books Online, precision is: p (precision) The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precisio...

Required Working Precision for the BBP Algorithm?

Hello, I'm looking to compute the nth digit of Pi in a low-memory environment. As I don't have decimals available to me, this integer-only BBP algorithm in Python has been a great starting point. I only need to calculate one digit of Pi at a time. How can I determine the lowest I can set D, the "number of digits of working precision"? ...

C++ floating point precision

Possible Duplicate: Floating point inaccuracy examples double a = 0.3; std::cout.precision(20); std::cout << a << std::endl; result: 0.2999999999999999889 double a, b; a = 0.3; b = 0; for (char i = 1; i <= 50; i++) { b = b + a; }; std::cout.precision(20); std::cout << b << std::endl; result: 15.000000000000014211 So.. ...

Floating Point Arithmetic - Modulo Operator on Double Type

So I'm trying to figure out why the modulo operator is returning such a large unusual value. If I have the code: double result = 1.0d % 0.1d; it will give a result of 0.09999999999999995. I would expect a value of 0 Note this problem doesn't exist using the dividing operator - double result = 1.0d / 0.1d; will give a result of 1...

Symfony 1.4 setter type double precision

Hi volks, I want to save a number with 14 decimal places, but symfony only saves 6. How can I control this: $loc->setSinRadLon(0.73946213661883); In the schema the column looks like: sin_rad_lon: { type: double(), scale: 14, notnull: true } The DB stetting is: sin_rad_lon double(18,14) In the DB the column value is: 0.73946...

How many double numbers are there between 0.0 and 1.0?

This is something that's been on my mind for years, but I never took the time to ask before. Many (pseudo) random number generators generate a random number between 0.0 and 1.0. Mathematically there are infinite numbers in this range, but double is a floating point number, and therefore has a finite precision. So the questions are: J...

Why does a C# System.Decimal remember trailing zeros?

Is there a reason that a C# System.Decimal remembers the number of trailing zeros it was entered with? See the following example: public void DoSomething() { decimal dec1 = 0.5M; decimal dec2 = 0.50M; Console.WriteLine(dec1); //Output: 0.5 Console.WriteLine(dec2); //Output: 0.50 Console.WriteLin...

Determine precision and scale of particular number in Python

I have a variable in Python containing a floating point number (e.g. num = 24654.123), and I'd like to determine the number's precision and scale values (in the Oracle sense), so 123.45678 should give me (8,5), 12.76 should give me (4,2), etc. I was first thinking about using the string representation (via str or repr), but those fail f...

Dividing a double with integer

I am facing an issue while dividing a double with an int. Code snippet is : double db = 10; int fac = 100; double res = db / fac; The value of res is 0.10000000000000001 instead of 0.10. Does anyone know what is the reason for this? I am using cc to compile the code. ...

C# precision loss when dividing a double

The function bellow is passed a string "1004233" and prints the following output: D1 = 1.004233 D2 = 0.00423299999999993 D3 = 4232.99999999993 D4 = 4232 I need D4 to print 4233 and not 4232. How do i stop this precision loss from happening? public string someFunc(String s){ string retval = "0"; try{ int id...

storing double values in SQLite: how to ensure precision?

hi there! i have a problem with double values i need to store in an android homed sqlite database. since these double values represent gps values (lat & lng), i really NEED an absolute precision down to the 9th number after the comma. now i have a table like this: CREATE TABLE x REAL lng; and insert sth (hardcoded) like: INSERT INT...

Byte precision of value in Python?

I have a hash function in Python. It returns a value. How do I see the byte-size of this return value? I want to know if it is 4-bytes or 8 or what. Reason: I want to make sure that the min value is 0 and the max value is 2**32, otherwise my calculations are incorrect. I want to make sure that packing it to a I struct (unsigned int) ...

32-bit versus 64-bit floating-point performance

hello. I have ran into curious problem. Algorithm I working on consist of lots of computations like this q = x(0)*y(0)*z(0) + x(1)*y(1)*z(1) + ... where the length of summation is between 4 and 7 The original computations are all done using 64-bit precision. For experimentation, I try using 32-bit precision for x,y,z input values (...