Click here to Skip to main content
15,902,777 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: FindFirstFile wants an unsigned short* ? Pin
Chris Losinger30-Dec-02 13:17
professionalChris Losinger30-Dec-02 13:17 
GeneralSetting cursor position in CComboBox Pin
The Lady of Shallots30-Dec-02 7:00
The Lady of Shallots30-Dec-02 7:00 
GeneralRe: Setting cursor position in CComboBox Pin
Nick Parker30-Dec-02 17:54
protectorNick Parker30-Dec-02 17:54 
GeneralRe: Setting cursor position in CComboBox Pin
The Lady of Shallots31-Dec-02 2:16
The Lady of Shallots31-Dec-02 2:16 
QuestionPost-Build commands? Pin
IGx8930-Dec-02 6:25
IGx8930-Dec-02 6:25 
AnswerRe: Post-Build commands? Pin
Chris Losinger30-Dec-02 7:15
professionalChris Losinger30-Dec-02 7:15 
GeneralRe: Post-Build commands? Pin
IGx8930-Dec-02 7:35
IGx8930-Dec-02 7:35 
GeneralDEBUG RELEASE not the same result!!! Pin
Raphael Kindt30-Dec-02 5:29
Raphael Kindt30-Dec-02 5:29 
Hello world...

I've writed a function
double FindValue(double X, int& prescaler, int& clk_freq)
where X is INPUT argument.
prescaler and clk_freq are OUTPUT arguments.
Here is the code:
double FindValue(double X, int& prescaler, int& clk_freq)
{
	const MAX_CLOCK = 16;
	const double Clock[MAX_CLOCK] = {26., 27., 28., 29., 30., 31., 32., 34., 36., 38., 40., 42., 44., 46., 48., 50. };
	double Min[4] = {0}, freq = 0;
	int i = 0, j = 0;

	// Seek prescaler
	for(i = 0; i < 4; i++, j = 0) {
		freq = X * pow(2, i);
		while( (j+1 < MAX_CLOCK) && (fabs(freq - Clock[j]) >= fabs(freq - Clock[++j])) ) {};
		if(j+1 == MAX_CLOCK) {
			Min[i] = min( fabs(freq - Clock[j-1]), fabs(freq - Clock[j]) );
		} else {
			Min[i] = fabs(freq - Clock[j-1]);
		}
	}
	for(j = 1, i = 0; j < 4; j++) {
		i = (Min[i] < Min[j]) ? i : j;
	}
	prescaler = (int)pow(2, i);

	// Seek clk_freq
	j = 0;
	freq = X * (double)prescaler;
	while( (j+1 < MAX_CLOCK) && (fabs(freq - Clock[j]) >= fabs(freq - Clock[++j])) ) {};
	if(j+1 == MAX_CLOCK) {
		clk_freq =  fabs(freq - Clock[j-1]) < fabs(freq - Clock[j]) ? (int)Clock[j-1] : (int)Clock[j];
	} else {
		clk_freq = (int)Clock[j-1];
	}
	return (clk_freq / prescaler);
}

The goal is to find the prescaler (=P) and the frequency (=F) where F/P = X (X is the INPUT wanted).
Values of P are limited to {1, 2, 4, 8} => pow(2, i) with i[0,3]
Values of F are limited to {26, 27, 28, 29, 30, 31, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50}
EXAMPLE:
if I want X = 20 then F must be 40 and P must be 2 because F/P = X

This function work fine with DEBUG mode but the result is different with RELEASE mode???!!!??? very strange...Confused | :confused: Confused | :confused: Confused | :confused:
In RELEASE mode I've found (for X = 20) F = 48 and P = 2... that's wrong
In DEBUG mode I've found (for X = 20) F = 40 and P = 2... that's OK

Thanks in advance for your assistances...


Hello World!!! Smile | :)
from Raphaël
GeneralRe: DEBUG RELEASE not the same result!!! Pin
nde_plume30-Dec-02 6:02
nde_plume30-Dec-02 6:02 
GeneralRe: DEBUG RELEASE not the same result!!! Pin
Raphael Kindt30-Dec-02 6:12
Raphael Kindt30-Dec-02 6:12 
GeneralRe: DEBUG RELEASE not the same result!!! Pin
Alvaro Mendez30-Dec-02 6:03
Alvaro Mendez30-Dec-02 6:03 
GeneralRe: DEBUG RELEASE not the same result!!! Pin
Raphael Kindt30-Dec-02 6:13
Raphael Kindt30-Dec-02 6:13 
General"Button capture" Pin
Adi Shavit30-Dec-02 4:40
Adi Shavit30-Dec-02 4:40 
GeneralSSH2 Protocol Pin
Nick Parker30-Dec-02 3:16
protectorNick Parker30-Dec-02 3:16 
QuestionWhy isn't modeless child dialog destroyed properly? Pin
Moak30-Dec-02 2:47
Moak30-Dec-02 2:47 
AnswerRe: Why isn't modeless child dialog destroyed properly? Pin
Gary R. Wheeler30-Dec-02 4:22
Gary R. Wheeler30-Dec-02 4:22 
GeneralRe: Why isn't modeless child dialog destroyed properly? Pin
Moak30-Dec-02 4:58
Moak30-Dec-02 4:58 
GeneralVC++ .net include directories Pin
Luke Murray29-Dec-02 21:57
Luke Murray29-Dec-02 21:57 
Generalctrl+alt+del Pin
r i s h a b h s29-Dec-02 19:17
r i s h a b h s29-Dec-02 19:17 
GeneralRe: ctrl+alt+del Pin
Dominik Reichl29-Dec-02 22:20
Dominik Reichl29-Dec-02 22:20 
GeneralRe: ctrl+alt+del Pin
r i s h a b h s29-Dec-02 23:09
r i s h a b h s29-Dec-02 23:09 
GeneralRe: ctrl+alt+del Pin
jmkhael30-Dec-02 1:56
jmkhael30-Dec-02 1:56 
GeneralRe: ctrl+alt+del Pin
Dominik Reichl30-Dec-02 7:32
Dominik Reichl30-Dec-02 7:32 
GeneralVirtual list VS Text Callbacks Pin
alex.barylski29-Dec-02 17:54
alex.barylski29-Dec-02 17:54 
Questioncrash in debug, but ok in release? Pin
zecodela29-Dec-02 17:01
zecodela29-Dec-02 17:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.