|
Richard,
I'm not trying to argue, just trying to find out what the spec says.
"THE 8087 PRIMER" is just a spec, from the Senior Staff Engineers at Intel Corp. explaining why they did what they did. How C uses the hardware should be specified somewhere.
Dave.
|
|
|
|
|
Member 4194593 wrote: I'm not trying to argue I did not mean to imply that you were; I am more than happy to have my assumptions corrected. As to what the C/C++ compiler should do in these cases, you could look at http://www.stroustrup.com/[^], or the Microsoft reference pages[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard,
Thank you for the links. I'll report back with anything I find (if I can understand it).
Dave.
|
|
|
|
|
Richard,
I did find out that a float cast as a (short) is truncated, but not yet found out about rounding in printf.
Dave.
|
|
|
|
|
Richard,
I did find out only that the number will be rounded to the number of specified precision digits, but there is no mention of which rounding method is used! I did send feedback that I was dissatisfied with their answer.
Dave.
|
|
|
|
|
|
jschell,
Thank you for the excellent link, at least it references a spec, namely IEEE.
Personally, I do not think it really makes any difference what the least significant digit is rounded to, but when you are converting a program and want to insure that the conversion is accurate, and the program has many options, the easiest approach is a batch file calling the two programs, supplying the different input files and options to be processed, and then using a file compare routine to compare the outputs for each test instance.
In the case of ENT compiled under Visual Studio 2008, I can see truncation, rounding to an even, and common rounding, all in one program. Makes it a bit difficult to "emulate" the original program.
I have examined all of the test output (the diffs) for all of the test instances, and all of my results match the ENT results except possibly for that last digit. At this point I am calling this a valid conversion, and a huge learning experience. At least my version is about 5 times as fast for huge files as ENT (16 GB - all DWORD values for a full 2^32 period) 6 min vs 28 min.
Dave.
|
|
|
|
|
I'm not sure if i should put this question in this forum or the Graphics forum, as the description in graphics forum only says DirectX,OpenGL or GDI.
So I was trying this graphics.h library that can crate simple graphic for console app. Everything works just fine until I multithreaded? it.
Ok, here is the code:
#include<graphics.h>
void drawrect(int l,int t,int r,int d,int col){
if(col==0)setcolor(RED);
else setcolor(BLUE);
rectangle(l,t,r,d);
}
void drawpiece(int l,int t,int r,int d,int col){
for(int i=1;i<5;i++)
drawrect(i*16+l,t,i*16+r,d,col);
}
DWORD WINAPI Thread2(void* lparam){
int px2=161,py2=17;
for(int i=0;i<10;i++,py2+=16,delay(100))
drawpiece(px2,py2,px2+16,py2+14,1);
}
int main()
{
initwindow(600,600,"TEST");
CreateThread(0,0,&Thread2,NULL,0,0);
int px1=17,py1=17;
for(int i=0;i<10;i++,py1+=16,delay(100))
drawpiece(px1,py1,px1+14,py1+14,0);
getch();
return EXIT_SUCCESS;
}
What i'm trying to do is to make two set of blockline. where first set is red and second set is blue.
this code makes the color mixed up.
So that's it. Any help would be greatly appreciated.
|
|
|
|
|
I have not checked your arithmetic, but it may be that the start points and limits of your rectangles are not correct.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I have checked the arithmetic and it works just fine if i don't multithread it.
This works just fine:
#include<graphics.h>
void drawrect(int l,int t,int r,int d,int col){
if(col==0)setcolor(RED);
else setcolor(BLUE);
rectangle(l,t,r,d);
}
void drawpiece(int l,int t,int r,int d,int col){
for(int i=1;i<5;i++)
drawrect(i*16+l,t,i*16+r,d,col);
}
int main()
{
initwindow(600,600,"TEST");
int px1=17,py1=17;
for(int i=0;i<10;i++,py1+=16,delay(100))
drawpiece(px1,py1,px1+14,py1+14,0);
int px2=161,py2=17;
for(int i=0;i<10;i++,py2+=16,delay(100))
drawpiece(px2,py2,px2+16,py2+14,1);
getch();
return EXIT_SUCCESS;
}
I'm really starting to think that this might be a problem from graphics.h
|
|
|
|
|
It may well be a problem with the graphics library (not the header) which is rather old and was probably not designed with multi-threading in mind. I would suggest you switch to one of the more current graphics libraries available in the Windows API.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Yes that's what i thought. I've switched to SDL and it works.
Anyway, thanks for replying to my question. Really appreciate it.
|
|
|
|
|
Hi,
This is very basic computer science problem. Look at your code cafefully.
First read all about context switching[^] and once you completely understand look over your code again.
Now ask yourself what would happen if ThreadA context switches in the middle of drawrect() and ThreadB continues execution of drawrect().
Best Wishes,
-David Delaune
|
|
|
|
|
David,
My reading of that is that it should, in theory, work. The variables used by each function are all stack variables and each thread has its own stack, so context switching should not affect it. I can only assume that there is some code in the actual library that is not thread safe.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
David,
Thanks for the reply, I've read about context switching and now I have so many question going on my head.
First thing first, what actually happen when you multithread? Does the processor run two or more processes independently at the same time , or does it still need to switch between processes?
because if it does run the two separately then why would it need to switch context?
another one is if it does run the two separately, then i'm guessing the function drawrect() can't be used at the same time and thus needs to be switched between processes. by logic, will it work if i apply semaphores to it?
So there you go. Can you help me with this? or did i confuse you with my questions?
|
|
|
|
|
Hi,
yudhistira dewanata wrote: First thing first, what actually happen when you multithread? Does the processor run two or more processes independently at the same time , or does it still need to switch between processes?
because if it does run the two separately then why would it need to switch context?
You would obviously need more physical cpu registers to execute processes completely independently if we define 'independently' as 'single task and never subject to context switches on the physical hardware'. Each operating system internally implements this in its own way[^].
I like to visualize engineering problems. As you are looking at my forum post... you can visualize your web browser application as being a node on a tree structure. The node at the very top is the probably the kernel and where the scheduling occurs. Multitasking [^] can be implemented in many ways.
yudhistira dewanata wrote: i'm guessing the function drawrect() can't be used at the same time and thus needs to be switched between processes. by logic, will it work if i apply semaphores to it?
No, because the function setcolor() is changing a global variable.
In fact I read your code before I read your question and I immediately saw the error. It is because I actually used these libraries many years ago.
Best Wishes,
-David Delaune
|
|
|
|
|
Ohh... I see...
Now i finally get it! Thanks a lot for the very good reply.
|
|
|
|
|
I am working on a project about data mining. my company has given me 6 million dummy customer info of twitter. I was assigned to find out the similarity between any two users. can anyone could give me some ideas how to deal with the large community data? Thanks in advance
Problem : I use the tweets & hashtag info(hashtags are those words highlighted by user) as the two criteria to measure the similarity between two different users. Since the large number of users, and especially there may be millions of hastags & tweets of each user. Can anyone tell me a good way to fast calculate the similarity between two users? I have tried to use FT-IDF to calculate the similarity between two different users, but it seems infeasible. can anyone have a very super algorithm or good ideas which could make me fast find all the similarities between users?
For example:
user A's hashtag = {cat, bull, cow, chicken, duck}
user B's hashtag ={cat, chicken, cloth}
user C's hashtag = {lenovo, Hp, Sony}
clearly, C has no relation with A, so it is not necessary to calculate the similarity to waste time, we may filter out all those unrelated user first before calculate the similarity. in fact, more than 90% of the total users are unrelated with a particular user. How to use hashtag as criteria to fast find those potential similar user group of A? is this a good idea? or we just directly calculate the relative similarity between A and all other users? what algorithm would be the fastest and customized algorithm for the problem?
|
|
|
|
|
|
Hello Friends
I am creating a MFC application in which adding Scrollbar to CDialogBar. But its not showing automatically when i open a file which displays some boxes in CDialog. When I click on scroll bar then only its showing up otherwise not.
Here am using like this to display scrollbar.
SetScrollRange(SB_VERT,0,4,TRUE);
SetScrollPos(SB_VERT,0);
ShowScrollBar(SB_VERT);
Thanks & Regards
Yogesh Sikri
|
|
|
|
|
Hello Mr. Sikri,
Please refer to the following:
http://msdn.microsoft.com/en-us/library/zz1h061h%28v=vs.80%29.aspx
You may find it useful to you problem.
Hope this helps!
Best of Luck!
With Kind Regards,
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:34am.
|
|
|
|
|
When pasting links into answers please make sure they are clickable, by using the "link" or "[^]" controls above the edit box.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hello everybody,
Does anybody know how to put commands in a ribbon markup file (for example a ribbon.xml )?
Here's the code:
<?xml version='1.0' encoding='utf-8'?>
<Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'>
<!-- Commands section -->
<Application.Commands>
<Command Name="cmdTab1"
Comment="The main tab of the ribbon."
Symbol="cmdTab1"
Id="500" >
<Command.LabelTitle>
<String Id ="501">Home</String>
</Command.LabelTitle>
</Command>
<Command Name="cmdButtonKillUapps"
Comment="Kill all user mode applications on the computer."
Symbol="cmdButtonKillUapps"
Id="11111" >
<Command.LabelTitle>
<String Id ="1214">Kill U. Applications</String>
</Command.LabelTitle>
<Command.LargeImages>
<Image Id="7097">res/kuAppsBlue.bmp</Image>
</Command.LargeImages>
<Command.SmallImages>
<Image Id="9802">res/kuAppsBlue16x16.bmp</Image>
</Command.SmallImages>
</Command>
<Command Name="cmdButtonKillKapps"
Comment="Kill all kernel mode applications on the computer."
Symbol="cmdButtonKillKapps"
Id="2222" >
<Command.LabelTitle>
<String Id ="5498">Kill K. Applications</String>
</Command.LabelTitle>
<Command.LargeImages>
<Image Id="2322">res/kuAppsBlue.bmp</Image>
</Command.LargeImages>
<Command.SmallImages>
<Image Id="1047">res/kuAppsBlue16x16.bmp</Image>
</Command.SmallImages>
</Command>
<Command Name="cmdButtonBlnkScrn"
Comment="Lock up and out computer of people on client(s)."
Symbol="cmdButtonBlnkScrn"
Id="502" >
<Command.LabelTitle>
<String Id ="503">Blank Screen</String>
</Command.LabelTitle>
<Command.LargeImages>
<Image Id="504">res/bscreenBlue_ico.bmp</Image>
</Command.LargeImages>
<Command.SmallImages>
<Image Id="505">res/bscreenBlue_ico16x16.bmp</Image>
</Command.SmallImages>
</Command>
<Command Name="cmdButtonDisaIn"
Comment="Turn off mice(s) and keyboard(s) as if the devices were unplugged from the computer."
Symbol="cmdButtonDisaIn"
Id="599" >
<Command.LabelTitle>
<String Id ="510">Disable Input</String>
</Command.LabelTitle>
<Command.LargeImages>
<Image Id="519">res/key_blanklock.bmp</Image>
</Command.LargeImages>
<Command.SmallImages>
<Image Id="554">res/key_blanklock16x16.bmp</Image>
</Command.SmallImages>
</Command>
</Application.Commands>
<Application.Views>
<Ribbon>
<Ribbon.Tabs>
<Tab CommandName="cmdTab1">
<Group CommandName="cmdGroup1" SizeDefinition="ThreeButtons">
<SplitButton CommandName="cmdButtonKillUapps">
<Button CommandName="cmdButtonKillKapps" />
</SplitButton>
<ToggleButton CommandName="cmdButtonBlnkScrn" />
<ToggleButton CommandName="cmdButtonDisaIn" />
</Group>
</Tab>
</Ribbon.Tabs>
</Ribbon>
</Application.Views>
</Application>
Like when I hover my cursor with my mice over a command it should show a box showing a title and a concise description of what it basically does.
I am using the Windows 7 S.D.K. with Visual Studio 2010 and comping this through an external executable called uicc.exe .
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
modified 27-Dec-12 20:48pm.
|
|
|
|
|
|
Yes, exactly what I was looking for, but how do you add return/enter spaces?, in C++ in a console application it is \n .
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
|
|
|
|
|