• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=Shammah;25002367]Some people tend to do the following: [code] #define Pi 3.141592 [/code][/QUOTE] He's using C++, not C. A const variable would be preferred.
[QUOTE=pikzen;25003993]By pasting it into the timer_tick method ?[/QUOTE] Nope I need to make it public somehow or pass in all the values, but I don't know how:frown:
[QUOTE=gparent;25004538]He's using C++, not C. A const variable would be preferred.[/QUOTE] C has consts too? We use the preprocessor anyway because :iia:
[QUOTE=ROBO_DONUT;25005349]C has consts too?[/QUOTE] Yeah but people who code C++ tend not to live in the 80s and instead embrace better ways of doing things, such as using an actual variable for constants.
People who code C++ tend to be just a little pedantic. :v:
[QUOTE=gparent;25007190]Yeah but people who code C++ tend not to live in the 80s and instead embrace better ways of doing things, such as using an actual variable for constants.[/QUOTE] [cpp]static const std::string piAddress = "www.angio.net/pi/digits/100000.txt"; template<typename T> struct Pi { operator T() { ::boost::asio::ip::tcp::iostream stream(piAddress); if(!stream) throw ::std::runtime_error("Cannot retrieve Pi from " + piAddress); T pi; stream >> pi; return pi; } };[/cpp] :v: It's having problems connecting though. Probably using the wrong protocol. Also, hidden code-duplication.
Because you'll obviously need 100000 digits :v:
[QUOTE=pikzen;25008056]Because you'll obviously need 100000 digits :v:[/QUOTE] Yeah, screw integers, you must now write a bignum class and use nothing else:v:
[QUOTE=ROBO_DONUT;24994180]Thank you :science: [editline]13:37[/editline] Oh :eng99: Well it's probably the right choice. Doing anything with strings is a huge pain in the ass in C, and C++ strings are probably a lot easier to work with.[/QUOTE] Yeah, almost any method of a C++ string returns a reference so it's easy to chain methods, and C++ strings have a built-in substr method and append method. And if you need a C string afterwards, you can always return a pointer to the internal char array representation, or copy it to another buffer.
[QUOTE=ROBO_DONUT;25007903]People who code C++ tend to be just a little pedantic. :v:[/QUOTE] I dunno, I don't feel like writing better code in the end is pedantic at all. EDIT: Not much difference in this case but in many others..
"Better" is a very subjective term, and I propose that it be deprecated in the next revision of the English standard. It's one of those words that is 100% guaranteed to start an argument due to its ambiguous nature. i.e. "ATI is better than Nvidia", "Soup is better than pudding", "C is better than C++", etc. As I have already adopted this policy, your statement "better code" threw a syntax error and I can happily pretend you didn't say it.
[QUOTE=ROBO_DONUT;25011680]"Better" is a very subjective term, and I propose that it be deprecated in the next revision of the English standard. It's one of those words that is 100% guaranteed to start an argument due to its ambiguous nature. i.e. "ATI is better than Nvidia", "Soup is better than pudding", "C is better than C++", etc. As I have already adopted this policy, your statement "better code" threw a syntax error and I can happily pretend you didn't say it.[/QUOTE] Soup is better than pudding though.
I just had soup. :)
[QUOTE=WTF Nuke;24675388]How do I use tinxml to go to an element? This doesn't work: [code] character.ToElement(currentmap); chracter >> maps.mapname; [/code][/QUOTE] No one knows do they? Is there another XML library that people do know how to switch to an element? A guy is breathing down my neck to start working again :saddowns:.
git is better than svn
[QUOTE=ROBO_DONUT;25011680]"Better" is a very subjective term, and I propose that it be deprecated in the next revision of the English standard. It's one of those words that is 100% guaranteed to start an argument due to its ambiguous nature. i.e. "ATI is better than Nvidia", "Soup is better than pudding", "C is better than C++", etc. As I have already adopted this policy, your statement "better code" threw a syntax error and I can happily pretend you didn't say it.[/QUOTE] It's not really subjective that type safety can be helpful, it's fact. But I know you don't seem to actually care at all and just want to write something that works. That's okay, I just like to go further than that.
[QUOTE=WTF Nuke;25013015]No one knows do they? Is there another XML library that people do know how to switch to an element? A guy is breathing down my neck to start working again :saddowns:.[/QUOTE] I don't understand what you're trying to do. What is going to an element?
I'm trying to place points on a map with Mercator projection, but latitude gives me a headache. There's a formula y=ln(tan(lat)+sec(lat)) on Wikipedia. It also says that Mercator projection is limited to +-85.05113 degrees in latitude. Somehow I must get the y coordinate between -397 and 397 to show it on the screen. I'm using a map from the Wikipedia article that should have maximum latitude at 80 degrees and the map fills my screen vertically. Can anyone help me do this?
[QUOTE=sim642;25018664]I'm trying to place points on a map with Mercator projection, but latitude gives me a headache. There's a formula y=ln(tan(lat)+sec(lat)) on Wikipedia. It also says that Mercator projection is limited to +-85.05113 degrees in latitude. Somehow I must get the y coordinate between -397 and 397 to show it on the screen. I'm using a map from the Wikipedia article that should have maximum latitude at 80 degrees and the map fills my screen vertically. Can anyone help me do this?[/QUOTE] If your y-coordinates are from m to n, (For example 0 to 100) I think you can do something like y = ( y - m ) * ( n / 794 ) - 397 to get it in the wanted range. That example is probably dysfunctional, though.
[QUOTE=esalaka;25018723]If your y-coordinates are from m to n, (For example 0 to 100) I think you can do something like y = ( y - m ) * ( n / 794 ) - 397 to get it in the wanted range. That example is probably dysfunctional, though.[/QUOTE] This always gives me the same y...
[QUOTE=sim642;25018886]This always gives me the same y...[/QUOTE] m should be replaced by the [B]lower bound[/B] of your y coordinates and n by the [B]upper bound[/B]. And that is the bounds [B]before[/B] the conversion, not after. 397 is the upper bound after it. [editline]06:28PM[/editline] Oh look, apparently it doesn't work like that. [editline]06:29PM[/editline] Let me think. Mapping a set of [B]m to n[/B] to the set of [B]o to p[/B] (Random variable names are random) should be easy. Why isn't it?
[QUOTE=esalaka;25018922] Let me think. Mapping a set of [B]m to n[/B] to the set of [B]o to p[/B] (Random variable names are random) should be easy. Why isn't it?[/QUOTE] I just copied this from Arduino wiki: (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min Seems to work after I figured out my minimum and maximum input values.
I was just gonna post that exact same equation. I actually have it in my calculator right now. To be exact, I graphed y=(x-0)((7-2)/(10-0))+2) with my calculator, where x is a value in the original range, 0 is the minimum input value, 10 is the maximum input value, 2 is the minimum output value and 7 is the maximum output value. The exact same equation, regardless.
[QUOTE=gparent;25014186]It's not really subjective that type safety can be helpful, it's fact.[/QUOTE] First of all, the issue of type safety does not apply to "#define PI 3.141592654" [i]at all[/i]. Second, you act as though there's only one way to enforce type safety. Type safety can be as simple as an explicit cast. Is: [code] float div(float a, float b) { return a/b; } [/code] any safer than: [code] #define div(a, b)\ ((float)(a)/(float)(b)) [/code] in terms of type safety? I really don't think so. Third, type "safety" is often not. Consider: [code] void set(int reg, int bit) { reg |= 1 << bit; }[/code] as opposed to [code] #define set(reg, bit)\ (reg) |= 1 << (bit) [/code] Doing set(PORTA, x) (where x is a floating-point value like 1.999999932) doesn't throw an error in the "type-safe" version, as 1.999999932 implicitly casts to the integer 1, which is almost certainly not what you wanted. The macro version correctly spots this error (left shift by a floating-point value) and refuses to compile. Finally, the form of type safety that you're advocating isn't really that useful if you practice certain other habits. I tend to do explicit casts to the types I need [i]where I need them[/i]. For this reason, I almost never have to worry about making type-safe functions or declaring all my constant values "const <type>". I honestly believe that if the programmers working on a project cannot function without things being one specific way, then type-safety, etc. is just obscuring a lack of fundamental understanding. Also, I don't believe in programming "taboos". These CS goons who drone on about how certain things, like the C preprocessor or the goto statement, are inherently evil only say these things because they or their peers don't know how to use them right. No tool is inherently evil, and programmers should be free to use them in any manner they wish as long as they [i]completely understand the implications of doing so[/i]. [QUOTE=gparent;25014186]But I know you don't seem to actually care at all and just want to write something that works. That's okay, I just like to go further than that.[/QUOTE] The ultimate measure of a program is whether it works. The manner in which you express your code is really nothing but details. The problem I have is that you always butt-in on things which are utterly trivial and act as though writing your code in some specific manner will allow a programmer to attain enlightenment or something. Please, for once, correct someone on something [i]useful[/i], like suggest a more appropriate approach to a problem in regards to its structure and algorithmic complexity. Your choice of method is far more important than your choice of letters and symbols.
[QUOTE=ROBO_DONUT;25021082]First of all, the issue of type safety does not apply to "#define PI 3.141592654" [I]at all[/I].[/QUOTE] double vs float. I've seen some funny calculations come out of this. [QUOTE=ROBO_DONUT;25021082]The macro version correctly spots this error (left shift by a floating-point value) and refuses to compile.[/QUOTE] That's just a good example of how understanding type safety can lead you to believe that the unsafe version is better. I'm perfectly fine with that. [QUOTE=ROBO_DONUT;25021082]I honestly believe that if the programmers working on a project cannot function without things being one specific way, then type-safety, etc. is just obscuring a lack of fundamental understanding.[/QUOTE] Glad we agree. [QUOTE=ROBO_DONUT;25021082]Also, I don't believe in programming "taboos". These CS goons who drone on about how certain things, like the C preprocessor or the goto statement, are inherently evil only say these things because they or their peers don't know how to use them right. No tool is inherently evil, and programmers should be free to use them in any manner they wish as long as they [I]completely understand the implications of doing so[/I].[/QUOTE] Glad we agree. But I don't go out of my way to avoid coding properly. Just because I know how goto works doesn't mean I always use it when it's unneeded. Similarly, just because I do not need const doesn't mean I'm stupid enough to not use it in my programs, because I know it can help you spot errors. [QUOTE=ROBO_DONUT;25021082]The ultimate measure of a program is whether it works. The manner in which you express your code is really nothing but details.[/QUOTE] Bullshit. See: bubble sort. [QUOTE=ROBO_DONUT;25021082]The problem I have is that you always butt-in on things which are utterly trivial and act as though writing your code in some specific manner will allow a programmer to attain enlightenment or something.[/QUOTE] Bullshit. I usually bitch about things that matter, and this is one of the few times where it was trivial. [QUOTE=ROBO_DONUT;25021082]Please, for once, correct someone on something [I]useful[/I], like suggest a more appropriate approach to a problem in regards to its structure and algorithmic complexity.[/QUOTE] I do that all the time too.
Anyone know how I could get updated data from an update thread to a render thread? I'm thinking of using a resource manager (basically a std::vector). Then using a critical sections when updating the state of non-static resource. How bad would critical sections be on performance for all my non-static resources? Is there a better way?
[QUOTE=DevBug;25021765]Anyone know how I could get updated data from an update thread to a render thread? I'm thinking of using a resource manager (basically a std::vector). Then using a critical sections when updating the state of non-static resource. [/QUOTE] You could also set some flag variable whenever there is new data, read the new data in the other thread and then flip that flag again. And not let the update thread access it before the flag is 0.
[QUOTE=esalaka;25021836]You could also set some flag variable whenever there is new data, read the new data in the other thread and then flip that flag again. And not let the update thread access it before the flag is 0.[/QUOTE] That would remove the whole purpose, unless InterlockedIncrement and InterlockedDecrement are much faster.
[QUOTE=gparent;25021346]double vs float. I've seen some funny calculations come out of this.[/QUOTE] I'm not sure I can say the same. Even floats have more precision than you usually need. I could probably come up with some cases where you [i]need[/i] a double if I really tried, but it's not an everyday problem. Also, a #define is no different than typing out 3.141592654 manually. It'll be whatever precision it needs to be. IIRC, it "prefers" double if you don't have the "f" suffix. [QUOTE=gparent;25021346]Bullshit. See: bubble sort.[/QUOTE] You totally misunderstood. I said "the manner in which you express your code". Your choice of algorithm is almost always important and I think is really what separates good programmers from bad. [QUOTE=gparent;25021346]Bullshit. I usually bitch about things that matter, and this is one of the few times where it was trivial. I do that all the time too.[/QUOTE] Meh. I probably went a little far, but I've seen you try to assert that one convention is "better" than another a few times where there's very little practical difference. Regardless, your posts have a good SNR and my criticism was unwarranted.
Programming in C Besides the fact that the value for output comes out slightly fucked up. Abserror and relerror keep making values way over what is expected. -removed- [editline]03:33PM[/editline] P.S. don't call me a retard because i code terribly, i'm doing next weeks works before we cover it. [editline]03:38PM[/editline] Also, please don't quote my code, this is for a course and I can't seem to figure out why its so fucked up.
Sorry, you need to Log In to post a reply to this thread.