GCD approximation for type double numbers

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
teleport
Messages
240
Reaction score
0
Hi, I am doing a phys experiment, and I find myself trying to obtain some pattern of quantization of some measurements, i.e., I'm trying to find a number (double) that divides at least a significant portion of my data, with an arbitrary remainder. Does anyone know of any algorithm that does this for type double numbers? I really need your help on this one. Thanks a lot.
 
Physics news on Phys.org
Code:
double mod(double n, double m) {
	if (n < 0)
		n = -n;
	if (m < 0)
		m = -m;
	int tmp = (int)(n / m);

	return n - tmp * m;
}