0
голосов
2ответов
1240 просмотров

efficient function to convert float/double to string

Right now, the only function that I am aware of is _snprintf_s like the following double dMyValue = <some value>; _snprintf_s(pszMyBuffer, sizeof(pszMyBuffer), 12, "%.10f", dMyValue);

1
голосов
2ответов
1740 просмотров

Double & Float method parameters execution when called in C#

Here's a small snippet of code, when called it outputs 'double'. Why? What's the reasoning behind this. Why doesn't it print 'float'? class source { static void Main() { Receiver r = new Receiver(); r.Method1(1.1); } } class Receiver { public virtual void Met...

12
голосов
1ответов
10317 просмотров

SSE register return with SSE disabled

I am in the following situation: I am writing code for a kernel that does not allow SSE instructions I need to do floating-point arithmetic I'm compiling for a x86_64 platform Here is a code sample that illustrates the problem: int main(int argc, char** argv) { double d = 0.0, dbase; ...

5
голосов
6ответов
2215 просмотров

Is there a Java equivalent of frexp?

Is there a Java equivalent of the C / C++ function called frexp? If you aren't familiar, frexp is defined by Wikipedia to "break floating-point number down into mantissa and exponent." I am looking for an implementation with both speed and accuracy but I would rather have the accuracy if I coul...

5
голосов
4ответов
5356 просмотров

Nth root of small number return an unexpected result in C#

When I try to take the N th root of a small number using C# I get a wrong number. For example, when I try to take the third root of 1.07, I get 1, which is clearly not true. Here is the exact code I am using to get the third root. MessageBox.Show(Math.Pow(1.07,(1/3)).toString()); How do I so...

81
голосов
17ответов
90014 просмотров

Double to string conversion without scientific notation

How to convert a double into a floating-point string representation without scientific notation in the .NET Framework? "Small" samples (effective numbers may be of any size, such as 1.5E200 or 1e-200) : 3248971234698200000000000000000000000000000000 0.00000000000000000000000000000000000023897...

1
голосов
1ответов
2048 просмотров

How to handle big integers (64 bit) numbers in tcl?

what is the best way to handle big integers in expr command. we know wide in expr.

1
голосов
3ответов
23241 просмотров

jQuery input validation for double/float

What's the best method to mask an input field to only allow float/double, without any jquery plugin. Acutally i'm doing it like this: $("#defaultvalue").bind("keypress", function(e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { ...

0
голосов
5ответов
2496 просмотров

Confusing type conversion - 2 Bytes to Double

I was recently asked to take over a project in which waveform data is sampled from a power converter and sent to an intelligent agent where calculations are done and the appropriate actions are taken based on the results. The following (java)snippet is what the previous coder used to convert t...

0
голосов
7ответов
4066 просмотров

How to divide two doubles accurately

I have two double a, b; I know that the following is true -1 <= a/b <= 1 however b can be arbitrarily small. When I do this naively and just compute the value a/b the condition specified above does not hold in some cases and I get values like much greater than 1 in absolute valu...

5
голосов
4ответов
11673 просмотров

How do you read floating numbers (REAL) from a sqlite database on the iphone?

I need to read floating point decimals from sqlite db I have created Variable type in database as INTEGER I am reading with sqlite3_column_int to NSInteger variables which parts should changed so i can read floating point integers from database thanks for answers sorry im a newbie in this t...

17
голосов
3ответов
25650 просмотров

How do I change my float into a two decimal number with a comma as a decimal point separator in python?

I have a float: 1.2333333 How do I change it into a two decimal number with a comma as a decimal point separator, eg 1,23?

6
голосов
3ответов
5305 просмотров

Comparing floating point values

I just read a statement about the floating point value comparison Floating point values shall not be compared using either the == or != operators. Most floating point values have no exact binary representation and have a limited precision. If so what is the best method for comparing ...

106
голосов
6ответов
39247 просмотров

Why is SSE scalar sqrt(x) slower than rsqrt(x) * x?

I've been profiling some of our core math on an Intel Core Duo, and while looking at various approaches to square root I've noticed something odd: using the SSE scalar operations, it is faster to take a reciprocal square root and multiply it to get the sqrt, than it is to use the native sqrt opco...

6
голосов
1ответов
2644 просмотров

Floating point stack handling with floating-point exceptions turned on

I'm running into an issue with floating point exceptions turned on in Visual Studio 2005. If I have code like this: double d = 0.0; double d2 = 3.0; double d3 = d2/d; and if I register an SEH handler routine, then I can easily turn the div-by-zero into a C++ exception and catch it. So fa...

5
голосов
9ответов
6858 просмотров

sin, cos, tan and rounding error

I'm doing some trigonometry calculations in C/C++ and am running into problems with rounding errors. For example, on my Linux system: #include <stdio.h> #include <math.h> int main(int argc, char *argv[]) { printf("%e\n", sin(M_PI)); return 0; } This program gives the foll...

0
голосов
5ответов
1453 просмотров

Operations for Long and Float in Python

I'm trying to compute this: from scipy import * 3600**3400 * (exp(-3600)) / factorial(3400) the error: unsupported long and float

7
голосов
8ответов
894 просмотров

What is the most efficient way to store and work with a floating point number with 1,000,000 significant digits in C?

I'm writing a utility to calculate π to a million digits after the decimal. On a 32- or 64-bit consumer desktop system, what is the most efficient way to store and work with such a large number accurate to the millionth digit? clarification: The language would be C.

44
голосов
13ответов
36669 просмотров

Check double variable if it contains an integer, and not floating point

What I mean is the following: double d1 =555; double d2=55.343 I want to be able to tell that d1 is an integer while d2 is not. Is there an easy way to do it in c/c++?

3
голосов
5ответов
6346 просмотров

double type digits in C++

The IEE754 (64 bits) floating point is supposed to correctly represent 15 significant digit although the internal representation has 17 ditigs. Is there a way to force the 16th and 17th digits to zero ?? Ref: http://msdn.microsoft.com/en-us/library/system.double(VS.80).aspx : . . Remember that...

2
голосов
3ответов
2015 просмотров

C++ version of isnormal()

Is there a C++ version of the isnormal, isnan and so C functions? I know I can use the C functions from C++, but I'm always interested to know if there are some C++-only alternatives.

1
голосов
1ответов
1027 просмотров

Using iPhone/Objective C CGFloats: Is 0.1 okay, or should it be 0.1f?

When using an iPhone Objective C method that accepts CGFloats, e.g. [UIColor colorWithRed:green:blue:], is it important to append a f to constant arguments to specifiy them explicitly as floats, e.g. should I always type 0.1f rather than 0.1 in such cases? Or does the compiler automatically cast ...

4
голосов
3ответов
6194 просмотров

Ruby: counting digits in a float number

Is there any worthy Ruby method to count the number of digits in a float? Also, how do I specify the precise when to_s float numbers?

0
голосов
2ответов
1035 просмотров

How do I set a float without using an OGNL converter?

I have a class that looks like this: public class Foobar { private float value; public void setValue(float value) { this.value = value; } } I then have a webpage (Struts2) that passed in a variable foobar.value. <input type="text" name="foobar.value" value="123.456"> I ...

1
голосов
5ответов
1097 просмотров

Why is x and y always 0 with a float?

int main(void){ float x =1; float y =2; while (x<y){ x = x +1 ; y = y +1; } printf("x is %d\n", x); printf("y is %d\n", y); } I would expect x and y to increase to the point we run out of bits, but it seems like x and y is alway 0 in this case...

0
голосов
2ответов
2054 просмотров

Converting from a text field to an numeric in Android

If I have an EditText component on my screen that I have specified inputType="decimal" for (i.e. a numeric/decimal field), what is the best way to convert it to an decimal value in the application code? Google recommends avoiding floats, and avoiding creating objects unnecessarily (and I assum...

3
голосов
2ответов
362 просмотров

Why is the number 16 converted to float(6.1026988574311E_320) by PHP using Zend_Amf

The Zend_Amf specification states that a Number type returned from flash will map to a float in PHP. Fine. But why does the number 16 get returned as 6.1026988574311E_320 ? PHP version is 5.2.9 running on OS X. I have tried forcing a cast to integer in PHP (the above value gets rounded to 0) and...

5
голосов
7ответов
1395 просмотров

Why is there a difference between the same value stored as a float and a double in Java?

I expected the following code to produce: "Both are equal", but I got "Both are NOT equal": float a=1.3f; double b=1.3; if(a==b) { System.out.println("Both are equal"); } else{ System.out.println("Both are NOT equal"); } What is the reason for this?

8
голосов
5ответов
3671 просмотров

Platform-independent way to obtain maximum C++ float value

What’s the best, platform-independent way to obtain the maximum value that can be stored in a float in C++?

0
голосов
1ответов
328 просмотров

How do you pass a float to ProgressView from another class?

I'm trying to pass ProgressView a float from a calculation made in another class. I've tried passing it by converting it to a NSDecimalNumber but I can't get it back to a float again when it reaches the destination. There's got to be a better way than this.