Labdabeta 182 Posting Pro in Training Featured Poster

Excellent explanation, as always. Thanks.

Labdabeta 182 Posting Pro in Training Featured Poster

Ok, just to check my understanding, you're saying that I cannot create 1 program that will be cross platform (in c++) but I can make a library that is cross platform by swapping in correct code at compile time (presumably using #ifdef directives). Then if I want my code to work on two systems I compile it twice, once with each OS specified?

Labdabeta 182 Posting Pro in Training Featured Poster

You cannot change a function's behaviour on an object, only on a class. To get the exact functionality you showed you would have to use a function pointer as a member of the test class:

class test
{// private:
    public:
    event<>(*Printed)();
    test()
    {
        Printed=[]{;}//I have yet to take a good look at the syntax for this
    }
};
test a;
a.Printed=[]{cout<<"\nMessage Printed\n";}

However this is not what people are usually referring to when they use polymorphism. Polymorphism is almost always used to represent the "is a" relationship where something changes. For example a square "is a" rectangle so this is proper practice for a square and rectangle class:

class Rectangle
{// private:
    int width,height;
    public:
    virtual int getArea(){return width*height;}
};
//time for polymorphism (technically here it is just inheritance)
class Square:public Rectangle
{// private:
    public:
    virtual int getArea(){return width*width;}
};

Because of the virtual label the following code would execute the following functions:

Rectangle r;
Square s;
Rectangle *rp;
Rectangle *rps=&s;//valid!
//Here width*height is called, as you would expect
r.getArea();
//Here width*width is called, as you would expect
s.getArea();
//Here, you still get width*height
rp->getArea();
//Here, since getArea was virtual, you get width*width
rps->getArea();

So basically to override a function in a new CLASS it is as easy as writing a new version of the function (virtual keyword is optional unless you deal with pointers to base classes). However overriding a function in a new OBJECT is very difficult.

cambalinho commented: thanks for try +2
Labdabeta 182 Posting Pro in Training Featured Poster

Thats what I thought. Thanks.

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

I am wondering how libraries create graphics contexts in a cross-platform manner. Somehow libraries like SDL create graphical windows seemingly without using the system headers. I know how to set up a window for graphics using Win32API, and how to get input from it using the same. How do I write a program such that it can be executed on any system (linux in particular) without requiring a windows environment? Or would I have to create two versions of my program, one for windows and one for linux?

Labdabeta 182 Posting Pro in Training Featured Poster

Yes. C++ has inheritance as well as generic types. This gives it full objective polymorphism. Polymorphism is actually one of the things for which C++ is famous http://lmgtfy.com/?q=C%2B%2B+Polymorphism .

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

I noticed that in c++ everything that can be done using a static function in a class could be done by using a public function in the same namespace. Assuming that you bind your classes in a namespace these functions do not take up names in the global namespace. As such I was wondering when to use static functions in classes and when to use public functions. For an example here is the current situation where I cannot decide which to use:

class Sprite
{// private:
    //Some image data
    public:
    //some functions
    Sprite &applyPoints(vector<Coord2D> ps,Colour c);//applies the given colour to a set of points
    //Now I want to make it easy to draw bresenham lines without writing the algorithm yourself:
#ifdef STATIC_VERSION
    static vector<Coord2D> getLineCoords(Coord2D start,Coord2D end);
#else
    vector<Coord2D> getLineCoords(Coord2D start,Coord2D end);
#endif

When, if ever, is it appropriate to use the static version and when, if ever, is it appropriate to use the public version?

Labdabeta 182 Posting Pro in Training Featured Poster

It is completely situational. Here is an example:
1000001

What is that number?
If you interpret it as a 7-bit unsigned number you get 65.
If you interpret it as a 7-bit sign/magnitude number you get -1.
If you interpret it as 1's complement you get -63.
If you interpret it as 2's complement you get -64.
If you interpret it as 8-bit 2's complement (very common) you get 65.
If you interpret it as an ASCII character you get 'A'.
If you interpret it as BCD (binary coded decimal) you get 41.

Basically you can represent anything which is countable using only 1s and 0s, and similarly every set of 1s and 0s can represent any number of things. The only way to know which interpretation to use is by situation.

In any given assembly language they will usually tell you exactly what things mean. Incidentally, once you assemble your code in assembly it will be turned into another number. For example in MIPS assembly (as described by my professor) you have:

add $1,$2,$3 = 0000 0000 0100 0011 0000 1000 0010 0000

The key is that n bits can represent 2^n possible 'thing's you need to define what 'thing' you want them to represent. In the case of 1s or 2s complement you just look at the first bit, if it is 1 the number is negative:

1011 in 4 bit 2's complement = -5
1011 in 8 bit …

ddanbe commented: Good advice. +15
Rahul47 commented: That was helpful. . . thankx +3
Labdabeta 182 Posting Pro in Training Featured Poster

I searched through the code, and it took long enough that lightning struck something and my computer died. On restarting code::blocks all my watches were deleted.

Apparently I somehow broke my debugger causing it to throw sigsegs on one of my odd vector types. Since index, indexed said vector, once it got to a valid value my debugger threw a sigseg. I found this out because without watches it worked fine. Also it turns out that I can just... push through the sigseg (I can hit F7 and just continue debugging without any noticeable side effects).

I think my Code::Blocks setup uses GDB to do its debugging... can anybody explain how GDB 'watches' work? It seems that they just call c_str() on most items to get their value, so how can one 'watch' an std::vector?

Labdabeta 182 Posting Pro in Training Featured Poster

This is more of a tale of "I think I broke it". Basically as an assignment for CS I have to write an assembler for a subset of the MIPS assembly language. Currently it is not working, getting a sigseg, so I decided to debug the code and step through it line by line. Every time I reach line 65 I get these messages from Code::Blocks:

At D:\C++\MIPSAssemblerCS241\asm.cc:65
Program received signal SIGSEGV, Segmentation fault.

On top of that I get little pop-up windows in the corners warning me about the very same segmentation fault.

As such I naturally inspected line 65 of my code. This is a copy-paste of it:

    size_t index=0;//we are at the 0th instruction

I am fairly certain that such a line can in no way cause a segmentation fault, and my code uses no multithreading, so have I broken my debugger somehow? or is there really a type of segmentation fault that can occur at such a line?

Labdabeta 182 Posting Pro in Training Featured Poster

atoi does indeed only work with cstrings, however you can convert an std::string to a cstring using .c_str(). So for your example I would guess that the solution is:

totalMins += atoi(MovieRecord->getMinutes().c_str()); 
Labdabeta 182 Posting Pro in Training Featured Poster

Ok, that makes some sense. I suppose even brand-new languages could be considered 'legacy' if they already have fallen into disuse enough to not be viable for an active forum. Thanks.

Labdabeta 182 Posting Pro in Training Featured Poster

I believe the true answer is irrelevant. Firstly it could differ based on implementation, and it is entirely possible that if it currently does have a limit, it would be removed in future. The big issue is that whether or not you have space for something is irrelevant.

There are certain numbers that are just so incredibly massive that they are assumed to be impossible to compute (http://en.wikipedia.org/wiki/Transcomputational_problem).

As it turns out 50! is not really all that big (relatively speaking) coming in at only 65 decimal digits. As such I would not be surprised if BigInteger COULD calculate it.

The thing is that if you start pushing the envelope of how big a number you can calculate you run into the wall of time and space. The algorithms will take time to run and there wont be enough space to run them. This is where the definition of a transcomputational problem comes in. A transcomputational problem is one which would take a computer the size of the earth longer than the age of the earth to compute. Obviously BigInteger frankly will be unable to deal with this, and even if it could it wouldn't matter since you could never get the output you need from it.

Luckily there are some clevel argorithms to keep big number use in check, often relying heavily on modular arithmetic (http://en.wikipedia.org/wiki/RSA_%28algorithm%29). If you really want to have fun with big numbers you will likely have to find a way to …

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

I have recently decided to learn TeX for note taking purposes (both my parents are doctors, I inherited my handwriting from them, my class notes up until now look somewhat like the voynich manuscript) since MS Word takes far too long to type equations into.

Overall it is going smoothly, but I did have a couple questions about TeX that weren't in the TeXbook. As such I did what I always do, I came to daniweb for help. I was quite surprised, then, when I could not find an appropriate place to ask my question.

Is it possible to create a TeX/LaTeX tab, perhaps under Software or Web Development? Or perhaps a new tab is in order, a sort of "Typesetting" tab if you will. Honestly I think the best bet would be to have a "Other Software" tab, since we also lack forums for statistical software, wolfram mathematica, etc. What do you think?

Labdabeta 182 Posting Pro in Training Featured Poster

No, that is not what this website is for. You should try it for yourself and then ask for help with a specific problem.

Labdabeta 182 Posting Pro in Training Featured Poster

Perhaps see how many of these you may wish to include: http://en.wikipedia.org/wiki/List_of_mathematical_functions

Other than that, if you finish early and want an extra challenge you can modify your program to be "arbitrary" precision. IE: with integers/rationals infinite precision and with irrational numbers some set, very high, precision.

Finally, I agree that UI should be the last thing you do. If you use proper OOP it shouldn't be an issue.

iamthwee commented: well said +14
Labdabeta 182 Posting Pro in Training Featured Poster

I still do not believe that is what is desired here. What seems to be the goal is some function like vector<string> getAllPalindromes(string str) that returns all palindromes in a string. So for example, getAllPalindromes("No lemon, no melon!") should return {"nolemonnomelon","olemonnomelo",...,"onno","nn"}.

As far as I can tell there is no more efficient way to do this than to loop letter by letter and check each substring for palindromes.

IE:

vector<string> getAllPalindromes(string str)
{
    vector<string> ret;
    for (int i=0; i<str.length(); ++i)
    {
        for (int ii=str.length()-1; ii>(i+1); --ii)//the i+1 is to eliminate 1 letter palindromes
        {
            if (isPalindrome(str.substr(i,ii)))
            {
                //add the string, and all its inner strings to ret
                //so "kayak" would add "kayak", and "aya" to ret
                i=ii;//skip ahead to the end of that sub-palindrome
                //break; the inner loop should break itself anyways.
            }
        }
    }
    return ret;
}
Labdabeta 182 Posting Pro in Training Featured Poster

Technically there is Furer's algorithm, however it has enough overhead that it is rarely used. Indeed it has slightly better asymptotic performance than the Schonage-Strassen and is, in a sense, a generalization thereof.

You can read about it here: http://www.cse.psu.edu/~furer/Papers/mult.pdf

(Credit for the link has to go to rubberman, its taken from a reply to my question in the c++ thread entitled Furer's algorithm)

The complexity of the Schonage-Strassen is O(nlogn*loglogn) whereas the complexity of furer's algorithm is nlogn*2^(O(log*n)) or equivalently(-ish, read about the iterated logarithm) nlogn*2^O(loglog...loglogn). However for most real-world, or even hypothetical mathematics the difference between loglogn and log*n is negligible. Unless you are dealing with creating a hypothetical program (for theoretically working with transcomputable numbers) typically Schonage-Strassen is the best there is.

Of course it has been theorized that the lower bound for multiplication is O(nlogn) however no valid algorithms have been discovered for this. (unless you count Knuth's O(n) algorithm which is purely theoretical)

Hope this helps.

Labdabeta 182 Posting Pro in Training Featured Poster

I like JorgeM's version. Could you post the code?

Labdabeta 182 Posting Pro in Training Featured Poster

Your problem is that '0' is not the same as 0. '0' is actually 0x30 (IIRC).

However your entire algorithm has a fatal flaw. You should realize that rand() is random (or at least relatively close to random) which mean that any sequence of numbers is fair game for it. What would happen to your code if, for example, rand() always returned 4 (http://xkcd.com/221/) of course rand() shouldn't do this, but that doesn't mean it can't.

Instead you should use a shuffling algorithm. In general you take some list and swap random elements as many times as you want. For example:

void shuffle(int array[], int array_size)
{
    for (int i=0; i<array_size; ++i)
    {
        //swap(array[rand()%i],array[i]);
        int rnd=rand()%i;
        int tmp=array[rnd];
        array[rnd]=array[i];
        array[i]=tmp;
    }
}
Labdabeta 182 Posting Pro in Training Featured Poster

Honestly, no language right now is optimal. As has been clearly stated, it depends on the situation, and almost every language out there has situations where it would be best. You can google search for analogies easily (like this one http://compsci.ca/blog/if-a-programming-language-was-a-boat/ ).

The issue is that no matter which language you choose, as Randall Monroe puts it, "You'll never find a programming language that frees you from the burden of clarifying your ideas." (http://xkcd.com/568/).

In theory of course an optimized language could be created, depending on your optimization criteria it would be different. For example if you want to optimize for compressed size, brainf' is almost optimal, but if you optimize for readability it is not.

In short, you need to decide what 'best' (optimal) means in your situation. Do you want legibility? Speed? Power? Versatility? Small source files? Teh pro l33t ski11z (assembly looks like pro hax to the layman)? whichever you choose you will end up with a different language as 'best'. Typically there will be a few languages that fit the specs, in which case you pick your favourite one.

Labdabeta 182 Posting Pro in Training Featured Poster

You will need to provide more information. How are you storing the matrix in your program What do you want to do with it? and very importantly what have you tried so far? Unless you give us some code to work with we can't help you.

Labdabeta 182 Posting Pro in Training Featured Poster

In my programs I usually only encounter 3 types of epic one liners, they all use the ternary conditional operator extensively.
(all in c++)

Type 1: Conditional arithmetic - When I want to change how an equation behaves based on conditions. Example taken directly from the add function of my integer library: (i<s?v[i]:0)+(i<o.s?o.v[i]:0)+(carry?1:0).

Type 2: Inline switch statements - Any switch statement can be made inline with the ternary operator.

switch (x)
{
    case A:doA();break;
    case B:doB();break;
    case C:doC();break;
    default:doD();break;
}

becomes:

(x==A?doA():(x==B?doB():(x==C?doC():doD())));

Type 3: Complicated bitshifty stuff, typically to create inline hash functions. I can't think of a good example off hand, but they end up looking really cool.

However, I believe epic one liners are generally considered bad practice. That is why I try to keep a comment above each one that describes what the one-liner does.

Labdabeta 182 Posting Pro in Training Featured Poster

Now that I see it on a bigger screen the layout is growing on me. Just a comment, not sure whether to put in bugs or here, but ads underneath the transparent banner at the top come to front if you mouse over them, so it is hard to get at the menus. I'm honestly not sure if the transparent banner is worth it. It is a major contributor to the cluttered feel of the site right now. Granted it turns opaque when you mouse over it, but leaving it opaque all the time would look nicer IMO.

Labdabeta 182 Posting Pro in Training Featured Poster

I have a couple issues with the current layout.

1) Small version
When the browser is in maximized mode all of these issues are gone, however I always have my browser snapped to one side of the screen. When it is like this I lose access to "Last Updated by" and the dropdown menus, and other nice stylistic things. I think that there should be at least an option to get these back, even when the window isn't maximized.

2) A serious lack of unity
Some things have rounded edges, others are square. There are too many colours. Basically everything is cluttered. A bit of polish and tidying up will help.

Labdabeta 182 Posting Pro in Training Featured Poster

In both Firefox and Chrome, when I snap the window to the edge of the screen I no longer get the drop down menus from the bar at the top. IE: if I mouse over "Software Devolpment" I don't get the option to select a subforum. However, it works if I maximize my window. Is this intentional or a bug?

Labdabeta 182 Posting Pro in Training Featured Poster

I assume you are asking how to partition an array into two sub-arrays. This can be done like this:

void partition(int *src, int srclen, int *a, int alen, int *b, int blen, bool(*part)(int))
{
    a=malloc(srclen*sizeof(int));
    b=malloc(srclen*sizeof(int));
    int aindex,bindex;
    aindex=bindex=0;//set the indices to 0
    for (int i=0; i<srclen; ++i)
    {
        if (part(src[i]))//part is a function, it returns true if the element should go in b, otherwise it returns false
            b[bindex++]=src[i];//this line adds it to b and increments its index
        else
            a[aindex++]=src[i];//see above
    }
}
Labdabeta 182 Posting Pro in Training Featured Poster

That is the correct MANUAL way. However standard headers provide simple easy ways that are likely faster. For example atoi() converts a string like "1234" into an int like 1234 for you. Yes, you could write it yourself like so:

int atoi(char *s)
{
    int ret=0;
    for (int i=0; s[i]; ++i)
    {
        if (s>='0'&&s<='9')//if s is a digit
        {
            ret*=10;//shift
            ret+=s[i]-'0';//and add
        }
    }
    return ret;
}

The benefit of using the standard libraries is that they are fast and guaranteed to work. Both methods work fine, but as far as I know, it is generally considered best practice to use whatever standard libraries make your task easier. (although personally I prefer to rewrite the functions myself just so that I am sure that I fully understand exactly what they do)

In summary: Yes, that is the correct way (although if char x=5 then int i=(int)x; works better, but if char x='5' then int i=(int)(x-'0'); is correct).

Labdabeta 182 Posting Pro in Training Featured Poster

I was actually thinking of a more straightforward approach. Read the whole block into a string (so the string contains, for example, "12:30"). Then remove the punctuation (so "12:30" becomes "1230") then use atoi() or atol() or stringstream() to convert it to your integers. The benefit of this method is that you will not have to shift the numbers at all, and all of your dates/times should be whitespace seperated, which lends itself nicely to fstream or stringstream >> operators. Removing characters from a string is fairly simple:

//don't quote me on this, it is from memory
void removeFromString(std::string &str, char ch)//removes all occurances of ch in str
{
    int index;
    while ((index=str.find_first_of(ch))!=std::string::npos)
        str.erase(index,index+1);
}
Labdabeta 182 Posting Pro in Training Featured Poster

Take a look at the std::(o/i)fstream classes. They have everything you need. Once you have some specific code, we can help determine where you went wrong. Basically you will want to pull the numbers out of the time/dates (basically by ignoring the ./: characters) then translate them into the ints you want. there are many ways to convert strings to integers if you merely search for them (atoi and stringstream come to mind).

Labdabeta 182 Posting Pro in Training Featured Poster

Sounds like a good project. You should probably get started on it. This forum doesn't do your project for you, rather we help you with specific problems. For this project I would suggest you look at http://en.wikipedia.org/wiki/Insertion_sort and http://en.wikipedia.org/wiki/Merge_sort . Good luck.

Labdabeta 182 Posting Pro in Training Featured Poster

Actually what I will do is have the definition of AnotherClass in a secured header. That way I can check to see if it has been included, and if it has I know there is a problem. My issue is that I have a long chain of inherited classes (my java friends like every single insignificant "is-a" relationship to be inherited :( ) and I didn't want to have to write a friend line for each one. However, I suppose I will have to. Thanks.

Labdabeta 182 Posting Pro in Training Featured Poster

Oops, I forgot to ask one quick thing. Does friendship get inherited? If I have a 'most base' class. Could I put friend class ClassExposer; in it and have it carry to each object that inherits it. Or do I have to put it in each subsequent class?

Labdabeta 182 Posting Pro in Training Featured Poster

I tend to prefer Mikael's version a bit better, it seems less 'hack-y'. I actually had it implemented like that before, with a processor class that was a friend to all the other classes. I suppose I will be doing the same thing again. (I like friends a bit more than wrappers just because I find it easier to spread my code out that way). Thank you both though.

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

I have a chain of inherited classes like this:

class A
{
    protected:
    int a;
    public:
    int getA(){return a;}
};
class B:public A
{
    protected:
    int b;
    public:
    int getB(){return b;}
};

Based on that you can see that the public can only read the values in those classes, they cannot write them. However I would like to make a sort of overriding class that will allow those with access to it to modify the classes, like so:

class ExposedA:public A
{
    public:
    ExposedA &setA(int a){this->a=a;return *this;}
};
//here is where I am lost
class ExposedB:public B
{
    public:
    ExposedB &setB(int b){this->b=b;return *this;}
};

I would like to be able to also modify the a part of B, just as if I swapped ExposedA into the B class's inheritance instead of A. I could of course just inherit ExposedB from ExposedA, however I would like to be able to cast my ExposedB pointers to B pointers so that I could send them out in their unmodifyable state. Is this at all possible? (I looked into virtual access specifiers, they got me a bit confused but it seems like they could help?)

Basically this is my goal:

ExposedB *eb;
eb->setB(1)->setA(2);
B *safeB=(B*)eb;
int a=safeB->getA();
int b=safeB->getB();
//I want the following two lines to fail:
safeB->setA(1);
safeB->setB(2);
Labdabeta 182 Posting Pro in Training Featured Poster

Thank you. Unfortunately I cannot use reference_wrappers here because of the fact that it overrides the = operator. While this allows it to do what it has to do, it does mean that it cannot be documented as a normal reference. Instead I have decided to restructure the entire program using wrapper classes. In that way I also don't have to abuse the friend relationship, and it will be harder to hack (always an issue when writing games for programmers).

Labdabeta 182 Posting Pro in Training Featured Poster

That looks like exactly what I want... I just have to ask one question: To a person using that reference, in what ways does it act differently to a normal reference (IE: if I gave you the object and told you that it was a normal reference when in reality it was a reference_wrapper, how would it be any different?)

Labdabeta 182 Posting Pro in Training Featured Poster

The purpose of this is to create a sort of AI game, in which you have to write an AI. As such I use a large set of classes to represent the objects of the game, then I have a controller class like so:

class Controller
{// private: (so that the opponent can't somehow use them)
    virtual string getPassword()=0;//so the player can set a password on the objects they control
    vector<Object*> &objects;//to give them quick-easy access to all the game objects
    //other vectors here, more specialized, for the less experienced programmers
    //for example I have vector<Unit*> &myUnits; to get access to just the objects this player can control
    virtual vector<Order> getOrders()=0;//to ask the player for orders.
    friend class Processor;//every Object is a friend of processor, I include this line in all of them
};
//a typedef for the display functon to be supplied to the processor (lets you display the map however you wish)
typedef void(*DisplayAdapterFunction)(vector<Tile*>&,//the game world
                                      vector<Order>&);//the order list
class Processor
{// private:
    //some helpful functions
    public:
    bool runGame(Controller *p1, Controller *p2, string map, int mapWidth, DisplayAdapterFunction daf)
    {
        //a ton of logic to actually run the game.
        //I use references in the Controller vectors so that I can 'point' them at the control vectors I use
        // that way I don't have to copy the entire vector each turn.
    }
}

I am assuming that by making my vectors in the Controller class constant they can't change the values. However I would very much like …

Labdabeta 182 Posting Pro in Training Featured Poster

@Tumlee - Thank you very much. Exactly the answer I expected. Is there some macro that can tell you if C++11 is supported (so that you can make a header work in C++03, but write it in C++11 and just have C++03 issue a warning?

@sepp2k - Wouldn't your solution have to either copy or move data from o into 'data'? What I want is for 'data' to reference the same object as 'o' references. (also I didn't know that you could use initializer lists for functions other than constructors, is it actually standard behaviour?)

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

I was just noticing that the 'const'ness of references often causes me to rewrite a large chunk of my code with pointers. For example if I have a class that needs access to a large amount of data from another class I would love to use a reference. However the only way to do that is to assign the references in the constructor (at least as far as I know) and therefore I can't re-assign the class at all (without complicated pointer conversions). As such I end up going through all my private data declarations and changing my references to pointers. This of course forces me to search my code for all the times I used the reference so that I can cast it. Not to mention that the class with all the data is for use by others, not by me (group project) and some of the others aren't yet comfortable enough with pointers to deal with them properly (Java programmers that just learned C++ in class). I was wondering if there is a way to say do this:

class someDataClass
{// private:
    const largeDataType &data;
    public:
    someDataClass &setDataRef(const largeDataType &o){data@=o;}//new operator for reference copy?
};

Instead of having to do this:

class someDataClass
{// private:
    const largeDataType *data;
    public:
    someDataClass &setDataRef(const largeDataType *o){data=o;}
};

I would have thought that if it wasn't possible that C++11 would have fixed that, given that it created the && move constructor, why couldn't it create some kind …

Labdabeta 182 Posting Pro in Training Featured Poster

I'm sure a bunch of you have seen this already, but don't forget the alt-text. http://xkcd.com/1185/ Anybody want to implement DaniSort with that shiny new API?

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

I am about to move to a new home (with better internet) and I was thinking of buying a liquid cooling system so I can overclock my CPU and GPU(AMD FX-6100 Hex-Core and NVIDIA GeForce GTX 560 Ti respectiveley). I just do not really understand how liquid cooling works. There is a canada computers nearby (canadacomputers.com) where I can buy liquid cooling setups and my Coolermaster Silensio case has ports for liquid cooling. I am wondering where it gets the liquid. Is the liquid water? I have a large aquarium, can I use its water? How can I tell how fast I can safely clock my CPU/GPU with liquid cooling? How exactly do you do it safely (I have overclocked my CPU before, I just want to ensure I did it right).

Anyways, any info will be helpful.

Thanks.

Labdabeta 182 Posting Pro in Training Featured Poster

@rubberman I have looked at them, and none of them have allocation for transcomputable numbers. This is obviously because there is no reason to use them. However for this competition transcomputable numbers are fair game. All we care about is the theoretical computability. So even if it would take a computer the size of the earth and more than the lifespan of the earth to calculate a number, our programs shall still do it!

Anyways, by modifying how my files work to a more iterative style (instead of having files of files I just have a string of files, similarly to a linked list) I have been able to rewrite my recursive functions iteratively. So all is well.

rubberman commented: Neat! Hope you win... :-) +12
Labdabeta 182 Posting Pro in Training Featured Poster

It looks like the last one has what I need... This is going to be hard... Thank you!

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

As may be apparent from my previous posts, I am in a "If its worth doing, its worth overdoing" sort of competition with a friend of mine. Our goal is arbitrary precision integer arithmetic. I think I am close to getting the data storage working, but now I want to look at the complexity of my multiplication step. I already have it so that if the number is <MIN_MUL_NUM bytes in size then I use "Grade-School multiplication". When my number goes above that, but is still stored in an array (thus <8^sizeof(size_t) bytes) I use Toom-Cook (with k=5 if the other number would like to use Grade-School multiplication, but 3 otherwise). Once I switch over to file stored numbers I intend to implement a Schonhage-Strasse algorithm (I have yet to write it however). However I do have a relatively rapid means by which to determine if my number is far too large (using my header info I can search to see if I have >X files in use for storing the number). As such I would love to implement Furer's algorithm for true asymptotic optimality. However, search as I might I cannot find a description of it anywhere online. Is it just too complicated to use? Or is it protected by some kind of copyright? Where is it?!

Labdabeta 182 Posting Pro in Training Featured Poster

Before getting to the issue at hand, I need to mention that you are making your code a little harder to read because you have double x; and double value; as both global and local variables. Please move those into the main function, they have no place in the global namespace. In fact that could be part of your problem, your compiler (if it isn't standard) could be using those x/value rather than the ones in your sine function. Also instead of using a while loop this is the perfect place for a for loop: for (int count=3; count<=100; count+=2) will be a lot easier than the while loop. Also you really should put 100 into a constant global of some kind at the top of your program. I would suggest #define PRECISION_ITERATIONS 100 then use for (int count=3; count<=PRECISION_ITERATIONS; count+=1) that way if you ever have to change the precision from 100 to something else you won't have to search through your code, instead you just go to the top and change its value. (You could also ask the user to enter the number of iterations)

Now onto the formula. It looks like you just plugged in the formula given without understanding it. What your teacher is trying to get you to do is approximate sin/cos using a Maclaurin series. If you do not know what that means then I don't blame you. It often is not taught until 1st year university (thats when I was taught it). However …

Ancient Dragon commented: great :) +14
rubberman commented: To mis-quote AD, most excellent post! :-) +12
Labdabeta 182 Posting Pro in Training Featured Poster

That math is just my argument for the limitations on my program. It represents the largest number I could theoretically represent given my desired solution.

From what I understand of your reply, it seems as though my best chance at a solution is probably to just re-write my recursive functions to be iterative one way or another. I rarely use more than one loop per function unless I really have to, but I suppose in this case it will probably be necessary.

I'll mark this as solved if/when I succeed in my rewrites.

Labdabeta 182 Posting Pro in Training Featured Poster

The point is that we will determine exactly what will be the limitation on our programs, then we will look up the 'optimal' situation and see who could store the largest number. As such I use up a fairly large chunk of RAM, then I switch to a series of files. As such I am bounded only by (prepare for epic equation now):

(number of 1 byte digits)^(number of those in a file [31 bits worth of bytes=2^31 bytes])^(maximum files I can create MIN[(number of valid filename characters)^(FILENAME_MAX),free disk space/the stuff before the last ^]

=
using 55 valid file characters (A-Z, a-z, -, _, )

(256^(2^31))^min(55^260,(x/(2^31)))

=
using 13.2 TB hard disk space (http://www.cray.com/Products/Storage/Sonexion/Specifications.aspx)

(256^(2^31))^(13 200 000 000 000/(2^31))

Since there is no reason why an 'optimal' setup couldn't have many terrabytes of memory (by just having a super computer with tons of disks) I thought that if I use a recursive solution my bottleneck is likely to be a lack of RAM rather than a lack of hard disk space. The point of the competition is to think asymptotically, so I think I need some means by which to get these files working. However doing such things as multiplication/integer division on these files is no easy task!

(Note that with 13.2 TB like on the Sonexion I would end up with 13.2x10^12/(2^31)=6146 recursive calls, which is almost certainly enough to outrun my stack, especially seeing as each one will be a recursive call to …

Labdabeta 182 Posting Pro in Training Featured Poster

Hello,

First of all some background. My friend and I are having a bit of a competition over theoretically infinite number storage. We have agreed that the first person with a working arbitrary precision integer library with the theoretical ability to store an infinitely large number (IE: if the hard drive was big enough it would fill it up with the number) shall win. My plan has been to use .int files with the following format:

1-bit : Sign (1=positive, 0=negative)
31-bits : data (0=END)
data-bits : base 256 little endian number info
max FNAME_MAX-bits : next File (to be multiplied by 256^31 and added to this number)

I have it working, but only as a recursive function and I realized that this violates the theoretical infinity idea by relying on having enough space on the stack for all my recursive calls, which will be bounded by RAM and/or the system. Unfortunately some of my recursive functions (like my multiply function) are rather complicated, with multiple points of recursion, in multiple directions. I have been trying to convert them to iterative formats, to no avail. I am wondering if there is a general way to convent a recursive function into an iterative one? If not does anybody have a more iterative solution to my infinite storage problem?

Labdabeta 182 Posting Pro in Training Featured Poster

Firstly, this is more of a code snippet than a discussion thread, no? Secondly the methodology you used is flawed. Instead of getting input inside the class functions you should move it outside. Instead of enqueue() you should use enqueue(int val) so that you can add values to the queue however you want. This is very important because lets say for example you have to get your values from a file. To use your code you would have to redirect cin to that file, and probably cout to a file too to keep messages from popping up. However if you use proper modularization this is not an issue. Always try to create classes that act as generally as possible so that they can be reused repeatedly. For example a queue should ONLY be a queue, not a queue and an input parser! As such I would suggest the following improvements:

A) Use standard names. For queues typically the functions are called enter and leave (enter adds an element to the queue, leave removes one and returns it).
B) Allow for input to the enter function so that all it does is store things.
C) If you are comfortable with them, this is the perfect chance to use a template parameter so that instead of being an integer queue, your queue class is just a queue.
D) Remove the using namespace std; line, it means that anybody using your code also has to use the std namespace, which …