i have two different programs that compare float and double variales and gives output , i shown that below : 1. #include<stdio.h> main() { int r; float f=22.5; double d=22.5; r=(f==d); printf("r=%d",r); } **Output:- r=1** 2. #include<stdio.h> main() { int r; float f=22.7; double d=22.7; r=(f==d); printf("r=%d",r); } **Output:- r=0** why this happen that for 22.5 both are same and gives o/p 1 and 22.7 both (f & d) are different and gives o/p 0

Member Avatar
Member Avatar
+0 forum 4

Hello, I wrote a library for arbitrary precision arithmetic recently and spent a long time implementing efficient multiplication algorithms. Now I am looking to see if it is possible for me to optimize anywhere else. One place that I thought should be more optimizeable is my division algorithm. Right now I use (hiding some internal implementation stuff): Int divide(Int numerator, Int denominator)const { if (denominator==0) return DIVIDE_BY_ZERO_ERROR; if (numerator==0) return 0; if (numerator.sign()!=denominator.sign())//result is negative return -((-numerator)/denominator); if (numerator==denominator) return 1; Int num=numerator.abs(); Int den=denominator.abs(); Int ret=0; while (num>den) { ret++; num-=den; } return ret; } Which is fairly slow, …

Member Avatar
Member Avatar
+0 forum 7

Solved

Member Avatar
Member Avatar
+0 forum 1

I need to calculate chi squared cdf from x->infinity with n=255 degrees of freedom. I cannot seem to get it to work. You can find formulae for chi squared distributions using google. Here is my non-functional approximation code: double riemannsum(double(*fnc)(double),double dx, double xmin, double xmax) { double ret=0; double x=xmin; while (x<xmax) { ret+=fnc(x); x+=dx; } return ret; } double lowergammaintegrand(double x) { return pow(x,254)*pow(M_E,-x);//I am only using 255 degrees of freedom in this program } double lowergamma(double x) { return riemannsum(&lowergammaintegrand,10,x,10000000); } double chicdf(double x) { static double gamma1275=3.40511e214;//this is Gamma(127.5)=Gamma(k/2) return lowergamma(x)/gamma1275; }

Member Avatar
Member Avatar
+0 forum 5

I have been using a Dell Vostro 1500 laptop for almost 4 years now. I purchased it to use in college and now that I am almost done my four year degree, I am wondering if it is time to move on and buy a new one. I know the "average lifespan" of a laptop is said to be about 4 years anyway. The only real problems I'm having are the slow and painful death of the battery (I can get a new one for about $50) and the 2GB of RAM really seems to be showing in the computer's …

Member Avatar
Member Avatar
+0 forum 1

The program is supposed to compute the values of [URL="http://mathworld.wolfram.com/GammaFunction.html"]Euler's Gamma Function[/URL] using an infinite product (formula #15 in the link), and it does so decently for low values, but the error gets too big for bigger values. Using both Mathematica and Maxima for reference this is what I get for Gamma(19.9): Gamma(19.9)~9.0406e16 Mathematica and Maxima difference: 9.6e2 Difference between my functions and Mathematica: 1.79e11 Difference between both of my functions: 1.21e5 What surprises me as well is similarity of results for both of my functions, because the second one gets to multiply values like 1e66 and 1e-61, while the …

Member Avatar
Member Avatar
+0 forum 2

I am working in an older version of Python (2.6, I believe). I cannot update to the latest version because it is not currently compatible with the other program I need the code to run with so, unfortunately, the "decimal" module is not available to me (as far as I know). I am running a program that pulls numbers (monetary values) out of a csv file and does some basic math with them before sending the values to the other program being used. I cannot use int values because both dollars and cents are used, so I have to be …

Member Avatar
Member Avatar
+0 forum 4

I've had an idea for a class that, instead of storing a number as a single floating-point value, stores the exact value as two or more integers (in cases such as division, fractional exponents, or irrational numbers such as pi or e). The class would have it's own mathematical functions as methods, modifying the internal values and possibly storing additional values as needed, and returning a double. The point would be to always have the exact value, only rounding when returning a value. This sounds like a good idea to me, but i haven't seen it done before. Does it …

Member Avatar
Member Avatar
+0 forum 5

Hello, I am writing a program that integrates a function and returns the integrated value. The integration is to be performed from 0 to an upper limit which I specify. But the function I am integrating does not allow 0 to be used as the lower limit, as using 0 will result in Nan or infinity. So I am using a really small value as the lower limit. When I use a value such as 1e-8 or 1e-10 as the lower limit and integrate the function, the results are very close to each other. However when I tried to use …

Member Avatar
+0 forum 0

The End.