/* =========== FUNCTION sum64_32ui ============================= Purpose: -------- Description: ------------ // Function sum64ui // Operation: Performs 64bit unsigned sum between a 64 bit ui and a 32 bit ui: // term2 is supposed to be in msecs, so it is converted to 1/65536th of a second // before operating. // NOTE: It works if term2 is less than 2^32/65. */ // High precision Algorithm to obtain a multiplication by 65.536 using integer arithmetics: // A*65.536 = A*65 + A * (0.536) = A * 65 + A * 536/1000 = // = A * 65 + (A * 548)/1024 + (A * 55)/65536 + (A * 4)/1048576 + (A * 753)/1073741824 + sigma, // where sigma is the remaining round-off error. // This error is quite small: simulation on a PC gives 25 hours as the limit for // sigma < 1 msec. // Another way to write the formula is: // A * 65 + (A * 548)/2^10 + (A + 55)/2^16 + (A * 4)/2^20 + (A * 753)/2^30 + sigma. // So that the operations required are only multiplications and shifts. // This would neverthless limit A to be < 4,000,000 because the elapsed # of msec // should have to be multiplyed by ~ 1000 (548) // As A are msecs, this would limit A to be < 66.67 minutes, i.e. about only 1 hour // To avoid this, A can be splitted into two 16 bit parts, namely: // A = Ah * 2^16 + Al. Replacing A in this way, and neglecting quantities which are // always zero (both Al and Ah are < 2^16), we obtain: // (Ah * 548)* 2^6 + (Ah * 55) + Ah/2^2 + (Al * 548)/2^10 + (Al * 55)/2^16 + (A * 65). // In this way the dynamics of the operation is raised to the full span of 65536 secs, // namely to 18 hours. // Note: the remainder > 1 for the high part is not handled at all // because it can happen only when the elapsed time is > 65536 secs. // =========================================================================================