Developing a little vector library, any thoughts? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
19th Apr 2019, 3:43 PM
Chum4k3r
Chum4k3r - avatar
6 Answers
+ 1
Any of the above mentioned, and any other that might come to mind :D I'll be glad to learn and improve! Right now I've just made the basic operations work elementwise with as many operand vectors as needed, in a single call. But the v_div function still needs a handle to the 0/0 case, which I'm considering to return 1. The x/0 case return 2 to the power of 32, but still needs a handle to the -x/0 case, that is returning the same as x/0, but should be negative...
21st Apr 2019, 6:55 AM
Chum4k3r
Chum4k3r - avatar
+ 1
Amazing! Thank you so much!! -----------edit: Just updated the code with your suggestion on the pointer type and the initializer, also posted the destroyer and a few trigonometric functions.
21st Apr 2019, 6:04 PM
Chum4k3r
Chum4k3r - avatar
+ 1
Just like heaven! So, the cheking would be something like the vector vout = _initialize(vin->size); if(!vout) printf("Some bad stuff happened, sry bro"); exit(-1); //Continue the code edit:--------- just made the adjustments you proposed, also made a macro for the checking hehe I think it's all nice untill now
23rd Apr 2019, 9:59 AM
Chum4k3r
Chum4k3r - avatar
0
Thanks for your reply! Actually I tried some sort of "destroyer" on my offline copy, but wasn't working properly, mostly because I didn't understand the "free" function when wrote that destroy(). I'll update it here ASAP . As for the static and not including on the header, I had no clue about how to make them really "private", again thank you! About the NULL protection, is it better to keep using malloc, or calloc would do it with more safety?
21st Apr 2019, 12:31 PM
Chum4k3r
Chum4k3r - avatar
0
On the first check if(!v) return v; It is saying that if the memory for "v" isn't successfully allocated, it is returning the non-existing pointer? And can I understand it as return NULL; like on the last checking's "else"?
22nd Apr 2019, 7:11 PM
Chum4k3r
Chum4k3r - avatar
0
Thank you, I'm really happy that you see me this way. I altered the code, already, and am putting it to rest for a while as some work from college is beginning to take my time. Again, thank you very much for all the help and interest, you certainly are an amazing person, as I've seen that you enthusiast on helping many folks around SL, this is really cool!
28th Apr 2019, 2:47 PM
Chum4k3r
Chum4k3r - avatar