What's the fastest way to compare sign on a double?
I know that a double has a "sign bit" but I'm not sure if the way I'm "looking for it" in its binary rep is a good idea or not.
Barring "portability" issues, can someone tell me what's going on with this code in MSVC++?
#include <stdio.h>
int main()
{
double z = 5.0 ;
__int64 b...
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?
...
I keep getting this weird output from my code everytime I use the 'start without degugging' (ctrl-F5) as opposed to normal 'debug' (F5).
When I try to find the following value of norm_differnece in debug (pressing F5) mode, it gives me the correct answer for norm_difference
normdifference = 1.000000
but in 'start without debugging' (...
Does CUDA support double precision floating point numbers ? Also need reasons for the same.
...
Hi,
I get on trouble using gfortran on OpenSolaris 2009.06 64bit. I compile mine (gcc-4.4.1) or use the one provided by OpenSolaris package system (gcc-4.3.2).
But I'm in trouble using this simple code (extract from the more complexe one I targeted) :
PROGRAM TESTPRGM
REAL test;
test=-1.14739E+002;
writ...
Is there in the STL or in Boost a set of generic simple comparison functions?
The one I found are always requiring template parameters, and/or instantiation of a
struct template.
I'm looking for something with a syntax like :
if ( is_equal(x,y) )
{
...
}
Which could be implemented as :
template <typename T>
bool is_equal(const ...
In learning how floating point numbers are represented in computers I have come across the term "bias value" that I do not quite understand.
The bias value in floating point numbers has to do with the negative and positiveness of the exponent part of a floating point number.
The bias value of a floating point number is 127 which means ...
Suppose you want to compute the sum of the square of the differences of items:
$\sum_{i=1}^{N-1} (x_i - x_{i+1})^2$
the simplest code (the input is std::vector<double> xs, the ouput sum2) is:
double sum2 = 0.;
double prev = xs[0];
for (vector::const_iterator i = xs.begin() + 1;
i != xs.end(); ++i)
{
sum2 += (prev - (*i)) * (prev - (...
Hi Guys,
I am trying to use sinf function in my C Program and it does give me undefined reference under MSVC 6.0 but sin works fine.
This make me curious to find the difference between sin and sinf.
What is the logical difference between sin and sinf().
How can I implement my own sinf functionality?
...
In a multiplayer game I'm developing, we have a few values that are floating point numbers. The back-end (in PHP) and the front-end (in Flash) occasionally perform the same calculations on these numbers, to minimize communication.
I am currently making sure that both sides are using 64-bit doubles, but am I safe to assume that all calcu...
Hi,
I’m using a log-based class in C++ to store very small floating-point values (as the values otherwise go beyond the scope of double). As I’m performing a large number of multiplications, this has the added benefit of converting the multiplications to sums.
However, at a certain point in my algorithm, I need to divide a standard dou...
>>> num = 4.123456
>>> round(num, 3) # expecting 4.123
4.1230000000000002
I'm expecting 4.123 as a result, Am I wrong?
...
>>> from datetime import datetime
>>> t1 = datetime.now()
>>> t2 = datetime.now()
>>> delta = t2 - t1
>>> delta.seconds
7
>>> delta.microseconds
631000
Is there any way to get that as 7.631000 ? I can use time module, but I also need that t1 and t2 variables as DateTime objects. So if there is an easy way to do it with datettime, that ...
I'm interesting in the time cost on a modern desktop CPU of some floating point operations in order to optimize a mathematical evaluation. In particular I'm interested on the comparison between complex operations like exp, log and simple operation like +, *, /.
I tried to search for this information, but I could't find a source.
What ...
Hello!
I am facing a task where one of my hlsl shaders require multiple texture lookups per pixel. My 2d textures are fixed to 256*256, so two bytes should be sufficient to address any given texel given this constraint. My idea is then to put two xy-coordinates in each float, giving me eight xy-coordinates in pixel space when packed in ...
In Java the floating point arithmetic is not represented precisely. For example following snippet of code
float a = 1.2;
float b= 3.0;
float c = a * b;
if(c == 3.6){
System.out.println("c is 3.6");
} else {
System.out.println("c is not 3.6");
...
I am quite new in Python and I am looking for converting numbers from decimal to hex
How to convert float numbers to hex or char in Python 2.4.3?
how can I keep it to write it as ("\xa5\x (here the new hex number)")
any help
Thanks,
...
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.. ...
I'm programming in C++. I need to convert a 24-bit signed integer (stored in a 3-byte array) to float (normalizing to [-1.0,1.0]).
The platform is MSVC++ on x86 (which means the input is little-endian).
I tried this:
float convert(const unsigned char* src)
{
int i = src[2];
i = (i << 8) | src[1];
i = (i << 8) | src[0];
...
How do I type a floating point infinity literal in python?
I have heard
inf = float('inf')
is non portable. Thus, I have had the following recommended:
inf = 1e400
Is either of these standard, or portable? What is best practice?
...