Click here to Skip to main content
15,889,116 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Floating point arithmetic Pin
CPallini28-Jan-08 23:36
mveCPallini28-Jan-08 23:36 
GeneralRe: Floating point arithmetic Pin
Maxwell Chen28-Jan-08 23:39
Maxwell Chen28-Jan-08 23:39 
GeneralRe: Floating point arithmetic Pin
CPallini28-Jan-08 23:51
mveCPallini28-Jan-08 23:51 
GeneralRe: Floating point arithmetic Pin
User 345557728-Jan-08 23:53
User 345557728-Jan-08 23:53 
GeneralRe: Floating point arithmetic Pin
Maxwell Chen28-Jan-08 23:57
Maxwell Chen28-Jan-08 23:57 
GeneralRe: Floating point arithmetic Pin
User 345557728-Jan-08 23:57
User 345557728-Jan-08 23:57 
GeneralRe: Floating point arithmetic Pin
CPallini29-Jan-08 0:13
mveCPallini29-Jan-08 0:13 
GeneralRe: Floating point arithmetic Pin
User 345557729-Jan-08 1:46
User 345557729-Jan-08 1:46 
Sorry for the delay - just returned from lunch. Upon further investigation, the difference is between debug and release builds. Debug build compiles to fpu code:
	//double dRes2 = 0.0;
00C1A579  fldz             
00C1A57B  fstp        qword ptr [ebp-48h] 
	//for(int i=0; i<1024; ++i)
00C1A57E  mov         dword ptr [i],0 
00C1A585  jmp         CurrentFunction+0C0h (0C1A590h) 
00C1A587  mov         eax,dword ptr [i] 
00C1A58A  add         eax,1 
00C1A58D  mov         dword ptr [i],eax 
00C1A590  cmp         dword ptr [i],400h 
00C1A597  jge         CurrentFunction+0D4h (0C1A5A4h) 
	//{
	//	dRes2 +=d;
00C1A599  fld         qword ptr [ebp-48h] 
00C1A59C  fadd        qword ptr [ebp-28h] 
00C1A59F  fstp        qword ptr [ebp-48h] 
	//}
00C1A5A2  jmp         CurrentFunction+0B7h (0C1A587h) 


which gives the wrong result, while release builds SSE code (along with loop unrolling):
	//double dRes2 = 0.0;
004CAB82  xorps       xmm1,xmm1 
004CAB85  mov         eax,80h 
004CAB8A  lea         ebx,[ebx] 
	//for(int i=0; i<1024; ++i)
004CAB90  sub         eax,1 
	//{
	//	dRes2 +=d;
004CAB93  addsd       xmm1,xmm0 
004CAB97  addsd       xmm1,xmm0 
004CAB9B  addsd       xmm1,xmm0 
004CAB9F  addsd       xmm1,xmm0 
004CABA3  addsd       xmm1,xmm0 
004CABA7  addsd       xmm1,xmm0 
004CABAB  addsd       xmm1,xmm0 
004CABAF  addsd       xmm1,xmm0 
004CABB3  jne         CurrentFunction+80h (4CAB90h) 
004CABB5  movsd       mmword ptr [esp+38h],xmm1 
	//}


which gives an accurate result.

setting the FPU control word to double or extended double precision solved it - i guess either your FPU control word was already set right, or you tested it in release builds.

thanks for everyone's time!

modified 23-Jan-21 21:03pm.

GeneralRe: Floating point arithmetic Pin
Maxwell Chen29-Jan-08 4:33
Maxwell Chen29-Jan-08 4:33 
GeneralThe villain is found! Pin
User 34555776-Feb-08 1:06
User 34555776-Feb-08 1:06 
QuestionTimer Intervals Pin
Derick Magagula28-Jan-08 22:03
Derick Magagula28-Jan-08 22:03 
GeneralRe: Timer Intervals Pin
Cedric Moonen28-Jan-08 22:09
Cedric Moonen28-Jan-08 22:09 
GeneralRe: Timer Intervals [modified] Pin
Maxwell Chen28-Jan-08 22:09
Maxwell Chen28-Jan-08 22:09 
GeneralRe: Timer Intervals Pin
David Crow29-Jan-08 3:07
David Crow29-Jan-08 3:07 
GeneralRe: Timer Intervals Pin
Maxwell Chen29-Jan-08 4:35
Maxwell Chen29-Jan-08 4:35 
GeneralRe: Timer Intervals Pin
CPallini28-Jan-08 22:54
mveCPallini28-Jan-08 22:54 
QuestionWorking with CFile!!!! Pin
rowdy_vc++28-Jan-08 21:57
rowdy_vc++28-Jan-08 21:57 
GeneralRe: Working with CFile!!!! Pin
Maxwell Chen28-Jan-08 22:04
Maxwell Chen28-Jan-08 22:04 
GeneralRe: Working with CFile!!!! Pin
Cedric Moonen28-Jan-08 22:12
Cedric Moonen28-Jan-08 22:12 
GeneralRe: Working with CFile!!!! Pin
Maxwell Chen28-Jan-08 22:16
Maxwell Chen28-Jan-08 22:16 
GeneralRe: Working with CFile!!!! Pin
Cedric Moonen28-Jan-08 22:06
Cedric Moonen28-Jan-08 22:06 
GeneralRe: Working with CFile!!!! Pin
rowdy_vc++28-Jan-08 22:38
rowdy_vc++28-Jan-08 22:38 
GeneralRe: Working with CFile!!!! Pin
Maxwell Chen28-Jan-08 23:05
Maxwell Chen28-Jan-08 23:05 
GeneralRe: Working with CFile!!!! Pin
Rajesh R Subramanian28-Jan-08 22:51
professionalRajesh R Subramanian28-Jan-08 22:51 
QuestionProblem in AfxBeginThread Pin
gReaen28-Jan-08 21:35
gReaen28-Jan-08 21:35 

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.