|
a double is only a 64bit value. You can't get a 128 bit number out of that. You're going to have to find some other way of getting your precision.
Joseph Dempsey
joseph_r_dempsey@yahoo.com
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
--anonymous
|
|
|
|
|
double on Win32 is of course 64bit.
long double on SGI and on Sun is 128bit.
The question is - why does VC++ produce such a weird output?
I am not trying to get 128bit number out of Win32 double, I'm just trying to output it with 50 digits after the decimal point. And when I try to do that, I get completely wrong result. Borland C++ and g++ produce correct results on Win32.
|
|
|
|
|
Just a guess but I think it may be outputting the least number of digits required for significance.
|
|
|
|
|
The problem is quite different,
20
and
2000000000000000
are just very different numbers, it is not the same nubmer with a different number of digits after the decimal point .. there is no decimal point
|
|
|
|
|
Perhaps you'd want this instead:
void main( void )
{
double z = 20.0123;
for (int x = 1; x < 40; x++)
cout << setprecision(x) << z << endl;
}
|
|
|
|
|
It is a bug in Microsoft's STL when the precision is greater than _MAX_SIG_DIG and the formatted number doesn't contain any decimal point. Send the bug off to Microsoft and/or Dinkumware http://www.dinkumware.com/[^].
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I thought it is a bug, weird one. Thanks for the explanation.
|
|
|
|
|
Currently I'm considering my options with a small project and if it is posible I think the easiest way to do some of the data handling would be to read and write to the ASCII keyed files using VC++. And while I say this, I can't seem to find any online refferences on how to do this ... any suggestions?? As a little background info ... these keyed ASCII files where created and maintained originally in MTB
BASIC.
Thanks in advance ..... Bryan ~
|
|
|
|
|
You did not indicate that you're using the MFC, so I am going to assume you are ... check into CStdioFile class. That should give you the functionality you need/want.
D.
|
|
|
|
|
What do you mean by "keyed files".
Trust in the code Luke. Yea right!
|
|
|
|
|
Hello, my name is Alexander, I need urgent help with how to write a C++ program to read the data from an Excel spreadsheet (exported in fixed length format or comma delimited) to an object of the CFile class. Then, how to write a program to look at the records in the CFile object. Please, HELP
Alexander
|
|
|
|
|
|
Gee, if you submit this as your assignment, you might get 4.31/5.0, say 86%. I'll have to remember this, the next time I'm interviewing a Devry grad.
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"Microsoft hasn't ever enforced its patents. Apparently they keep them for defensive reasons only. Or, they could be waiting 'til they have a critical mass of patents, enforce them all at once and win the game of Risk that they're playing with the world." Chris Sells Feb 18, 2003.
|
|
|
|
|
Hey all.
Just wanted to ask if it is possible to make Visual Studio break whenever a given variable gets a specific value?
Thanks in advance.
-Rune Svendsen
|
|
|
|
|
One Word: "Softice"
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Just modify the breakpoint to be a conditional breakpoint.
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"Microsoft hasn't ever enforced its patents. Apparently they keep them for defensive reasons only. Or, they could be waiting 'til they have a critical mass of patents, enforce them all at once and win the game of Risk that they're playing with the world." Chris Sells Feb 18, 2003.
|
|
|
|
|
Yes. Set your break-point. Then press the ALT-F9 key to open up the BreakPoints watch window. Select the DATA tab. You'll now have the ability to set an expression based on a value. If you click on the ADVANCE button on that data tab, you can get really fancy.
D.
|
|
|
|
|
Dear all,
I can't borrow a book even though the code does not have any error. When I try to display the book details along with the member's name (in case the member has borrowed the book), I can't display the member's name, but only the book details and a message: "no member has borrowed a book".
Though the code works fine when I have one book and one member, but now that I'm using an array of books and members it doesn't work.
The code that displays the book and the member's name when I have 1 book and 1 member is:
<code>
void Book::display(Member* borrower)
{
cout<<"Book title and author are: "<<this->bookDetails<<"."<<endl;
if (borrower)
cout<<"The member's name is: "<<borrower->get_Data()/*get_name()*/<<"."<<endl;
else
cout<<"No member has borrowed a book."<<endl;
}
</code>
<code>
char* get_Data(){return this->name;}
</code>
<pre>returns the member's full name, entered in the constructor
I have an associationlist that holds pointers to associations. Each association has two pointers, one to a book object and the other to the member object.
<br />
class AssociationList<br />
{<br />
public:<br />
AssociationList();<br />
<br />
<br />
Member* get_data(Book* book);<br />
<br />
<br />
Book* get_data(Member* member);<br />
<br />
<br />
bool link(Book* book,Member* member);<br />
<br />
<br />
bool unlink(Book* book,Member* member);<br />
private:<br />
Association<Book,Member>* association_list[LIST_SIZE];<br />
};<br />
The code that performs the linking between 1 book object and 1 member object is the following:
<br />
template<class Book,class Member><br />
bool AssociationList<Book,Member>::link(Book* book,Member* member)<br />
{<br />
bool searching=true;<br />
bool success=true;<br />
int index=0;<br />
int free_slot;<br />
<br />
while(searching)<br />
{<br />
if(this->association_list[index])<br />
if((this->association_list[index]->linked_book()==book ||<br />
(this->association_list[index]->linked_member()==member)))<br />
{<br />
searching=false;<br />
success=false;<br />
}<br />
else<br />
index++;<br />
else<br />
{<br />
free_slot=index;<br />
index++;<br />
}<br />
if(searching&&(index == LIST_SIZE))<br />
searching=false;<br />
}<br />
if (success)<br />
this->association_list[free_slot]=new Association(book,member);<br />
return success;<br />
}<br />
Code that is used in the link function
<br />
template<class Book,class Member><br />
class Association<br />
{<br />
public:<br />
Association(Book* book, Member* member);<br />
<br />
Book* linked_book(){return this->book;}<br />
<br />
Member* linked_member(){return this->member;}<br />
<br />
private:<br />
Book* book;<br />
Member* member;<br />
};<br />
and
<br />
template<class Book,class Member><br />
Association<Book,Member>::Association(Book* book, Member* member)<br />
{<br />
cout<<"Association constructor called\n";<br />
this->book=book;<br />
this->member=member;<br />
}<br />
What needs to be done so that each member to be able to borrow one book?
(10-members)
(10-books)
(1 member can only borrow one book at a time)
Regards,
grscot
|
|
|
|
|
Dear all, I'm still struggling to display the book and borrower's details together.
Could someone help me?
regards,
grscot
|
|
|
|
|
I developed a simple object swap template. I simply do a binary swap of the class/structure contents. Yet I know that the developers of the STL libraries do not implement swaps in this way. Their implementation will make copies (via a copy constructor) and then use an assignment operator - "operator=()". The reason I want to do swaps in this manner is because of the obvious efficiencies. For instance, if I wanted to swap two branches of two very large tree structures, the copy and assignment operations become prohibative.
My question is in what instances does the code below NOT work?
template <typename _Ty>
void ObjectSwap(_Ty &obj1, _Ty &obj2)
{
// Don't swap on the same object
if (&obj1 != &obj2)
{
char tmp[sizeof(_Ty)]; // create a memory buffer
size_t sz = sizeof(_Ty);
memcpy((void *) tmp, (const void *) &obj1, sz);
memcpy((void *) &obj1, (const void *) &obj2, sz);
memcpy((void *) &obj2, (const void *) tmp, sz);
}
}
Scott K
|
|
|
|
|
I could see this working but it could lead to unexpected results if there are other pointers that point to the same object.
I'm confused though: why not just swap the pointers to the objects instead of the objects themselves? If you want to swap two branches of a large tree structure, you simply swap the pointers that point to those branches.
|
|
|
|
|
If an object contains one or more pointers to other objects, a simple bit-wise copy may not be what you want. Copy constructors and assignment operators let you do a so-called deep copy that addresses this. For example, suppose you have the following class:
class Stuff {
Stuff();
~Stuff();
int number;
char *string;
};
Stuff::Stuff()
: number(0),
string(new char[10])
{
strcpy(string,"Stuff");
}
Stuff::~Stuff()
{
delete []string;
} A bit-wise copy of one Stuff object to another simply copies the pointer to the string member. If one of the objects is then deleted, the other object's string member now points to freed memory. With a deep copy, you can ensure that each instance of the Stuff object has its own copy of the string:
class Stuff {
Stuff();
Stuff(const Stuff &stuff);
~Stuff();
int number;
char *string;
};
Stuff::Stuff()
: number(0),
string(new char[10])
{
}
Stuff::Stuff(const Stuff &stuff)
: number(stuff.number),
string(new char[10])
{
strcpy(string,stuff.string);
}
Stuff::~Stuff()
{
delete []string;
}
Software Zen: delete this;
|
|
|
|
|
Thanks, but my question was about swaping the contents of two objects. You are talking about copying an object - very different things. Using your example here is how you would manually swap the contents of two objects:
<br />
class Stuff <br />
{ <br />
Stuff(); <br />
~Stuff();<br />
void swap(Stuff &rhs):
<br />
int number;<br />
char *string;<br />
};<br />
<br />
Stuff::Stuff() : <br />
number(0),<br />
string(new char[10])<br />
{<br />
strcpy(string,"Stuff");<br />
}<br />
<br />
Stuff::~Stuff()<br />
{<br />
delete []string;<br />
}<br />
<br />
void swap(Stuff &rhs)<br />
{<br />
int tmpNumber = number;<br />
number = rhs.number;<br />
rhs.number = tmpNumber;<br />
<br />
char *tmpString = string;<br />
string = rhs.string;<br />
rhs.string = tmpString;<br />
}<br />
This will work 100% of the time if the object can guarantee that it manages the allocation and destruction of the string memory.
The code will obviuosly fail if the user somehow was able to assign stack allocated memory to the string pointer. In that case the Stuff destructor would try to delete a reference to stack memory - very bad thing to do.
My question then boils down to why would not the following swap code not work?
<br />
void swap(Stuff &rhs)<br />
{<br />
char tmp[sizeof(*this)];<br />
memcpy((void *)tmp, (void *)this, sizeof(*this));<br />
memcpy((void *)this, (void *)&rhs, sizeof(*this));<br />
memcpy((void *)&rhs, (void *)tmp, sizeof(*this));<br />
}<br />
|
|
|
|
|
Really what you are asking is, "Why can't you just change the memory location of an object?"
The answer is that other objects may be referencing it. If you use memcpy, it is not possible for the affected pointers to be fixed, like they could if you used copy constructors and/or assignment operators.
A linked-linked is a good example. If you swap nodes using memcpy, the list would become corrupted. Doing it the slow and safe way gives the objects the chance to reinsert themselves into the list correctly.
|
|
|
|
|
I have some(not actually few) html files that contain forms.I have a task to accomplish in this.
The task is, i get a string (typed by user while filling the form) and need to do a database lookup (through ODBC) and apply some algorithm(right now it is a dll written in VC++) to convert the data to the required form. The data typed by the user should go through this stage before getting submitted to the server.
What I want now is, I am struggling to find the correct way of doing it. Can it be an ActiveX control in VC? Then I need to sign it before using. Can I create a ATL HTML Control? But can other part of html call the function of this control (as like ActiveX)? I need to learn more abt that 'window.external', i suppose.
And what else can I do?
Thanx in advance,
Mahesh
|
|
|
|