MaaKa
There’s no need to get mad brother Just understand an accept the fact that he was trying to help But the help he provided wasn’t enough, and your both good 😊
Danya🔥
Wtf is going on here
B;
okk
So you get it now after two people told you the same thing
MaaKa
B;
Well nice. 👍
B;
Check this one
B;
https://pastebin.com/rCmkPdN5 Garbage value is getting printed idk why
B;
I recon it has something to do with indexing.
David
need a dev to code please
MaaKa
Code real world projects?
David
yes please
MaaKa
yes please
Ohh okay Someone may show up anytime soon I’m still working on console applications 😪
MaaKa
are you able?
No Just console applications for now 😮‍💨
Chijioke
Pls, what is the interpretation to; name[strlen(name)-1] = ' \0'
Chijioke
🙏Thanks. That is the '\n' now become '\0' , right?
Alexandr
I have some kind of message bus in my application and i need to track several int values at once. But this bus just for float type values. Is it save enough to reinterpret float as 4 uint8_t numbers? Or it depends on OS primitive sizes or something else?
Ludovic 'Archivist'
I have some kind of message bus in my application and i need to track several int values at once. But this bus just for float type values. Is it save enough to reinterpret float as 4 uint8_t numbers? Or it depends on OS primitive sizes or something else?
It is undefined behaviour, and some bits may be ignored when copying the resulting float values if it has specific values (for example, all the NaNs can be converted into another NaN without warning)
Alexandr
Is there some safe way? I need only two uint8_t btw
Chat Boss
Alexandr sent a code, it has been re-uploaded as a file
Ludovic 'Archivist'
Is there some safe way? I need only two uint8_t btw
IEEE754 floats can safely accommodate 16 bits integers
Daniel
在一个相当奇怪的时钟的表面上,小时数是从 1 到 12; 此时短针和长针都指向12。短针每小时顺时针移动2个数字,长针每小时顺时针移动3个数字。 多少小时后两根指针会再次指示相同的数字? (一) 8小时 (b) 15 小时 (c) 指针再也不会指示相同的数字 (d) 12 小时 (e) 19 小时
Sanchit
Double d = 456.54578 shows in c++ code while debugging is 456.545779999999998
Sanchit
Can anyone know any method of how i can take only 4 digits after decimal point for calculation in our code in decimal datatype
Sanchit
Is there any way that my decimal number will store only number like this - 456.5457
Sanchit
Actually i am doing calculation on all the numbers which contains decimal points
klimi
Is there any way for this
you can either have floating point or you can have whole number
Sanchit
you can either have floating point or you can have whole number
Actually in floating point the case is same i want it takes some garbage values after actual values in after decimal numbers
Sanchit
you can either have floating point or you can have whole number
I can not take whole number because i have all numbers with decimal points
klimi
Actually in floating point the case is same i want it takes some garbage values after actual values in after decimal numbers
floating points just divides the number, you cannot just do some calculation on part of the number
klimi
why do you need to take only part of it?
Sanchit
floating points just divides the number, you cannot just do some calculation on part of the number
Actually if you take flaoting point numbers like below Float a = 456.5478 it shows you while you debug the code as a= 456.547791
Sanchit
I want only four digits after decimal point i hope now you can understand
klimi
Actually if you take flaoting point numbers like below Float a = 456.5478 it shows you while you debug the code as a= 456.547791
floating point type is not precise, that's why you see a little difference; i don't get why you want 4 digits
Ludovic 'Archivist'
Can anyone know any method of how i can take only 4 digits after decimal point for calculation in our code in decimal datatype
Floating points are stored from real values using the shortest round-trip (taking a value that is converted back to a string would give you the same string) if applicable, or strict closest if not possible. Those are not, however, decimal numbers. Decimals in C++ can be relatively easily implemented, either as fixed precision or as multiprecision values.
Ehsan
Is there any way that my decimal number will store only number like this - 456.5457
hi i don't understand why are you interested in what precision debugger shows you, i think based on IDE you are using there are ways in the IDE's settings to show you specific number of digits after decimal point. but if you want a specific precision in your calculations float point is not your best choice. float points are based on IEEE 754 standard which is composed of sign bit, mantissa part and exponent part and based on your value uses the best precision and rounds it. if you want a specific precision in your calculations you better use fixed point arithmetic. and if you are interested in number of digits on console you must use iomanip library using fixed and setprecision(4) methods. google it. i hope it clear things a bit for you.
Sanchit
I know for console we have set precision method but i want to store only 4 digits after decimal point in a float or double variable
Sanchit
Is there any method for this
klimi
I know for console we have set precision method but i want to store only 4 digits after decimal point in a float or double variable
you set only how many decimal places you want to see, it gets converted from the floating point number to string of numbers, but internally it's the same float number
Ehsan
Is there any method for this
see if this works for you: #include <iostream> #include <cmath> int main() { float num = 3.14159265359; float truncated = std::floor(num * 10000.0f) / 10000.0f; std::cout << truncated << std::endl; return 0; }
MaaKa
Use this code It should work perfectly 🫠
Chat Boss
MAKA sent a code, it has been re-uploaded as a file
klimi
storing numbers as string is not recommended btw
klimi
it is unnecessary, you take memory without reason, you need to covert it and like you mentioned you cannot do arithmetic
klimi
there no reason to do arithmetics only on 4 decimal places if you have a float, this is just not how float works, if you want to work with decimal numbers, you will have to implement this by yourself
klimi
yeah, he didn't say he wanted just to print it or store it as string
Majid
Hello friends you have a complete binary tree training resource do you?
klimi
Hello friends you have a complete binary tree training resource do you?
http://cslibrary.stanford.edu/110/BinaryTrees.html
Guillermo
Hello friends you have a complete binary tree training resource do you?
I hope this can help you: https://www.amazon.es/Introduction-Algorithms-Press-Thomas-Cormen/dp/0262033844
Guillermo
It has a lot of theory about algorithms, not just BST's but a lot of more with practical exercises
Asiman
Hello guys. Is there any way to use vector of different object types but same parent class?
Chat Boss
D45 sent a huge message, it has been re-uploaded as a file hello i want to write a project, in which i want to use same class function in the another class..
Pavel
Hello guys. Is there any way to use vector of different object types but same parent class?
If you want to access them only through virtual functions base class, you can store them as unique_ptr to base class. Otherwise you can store them as std::variant or std::any
Pavel
can anybody help me with this?
You added definitions for new functions, instead defining your functions of the class, it should be something like this instead: int someClass::functionOne() { ... } void someClass::functionTwo() { .. }
Anonymous
hello i want to write a project, in which i want to use same class function in the another class function is it possible? for example: class someClass { public: int functionOne(); void functionTwo(); }; int someClass::functionOne() { // some code functionTwo(); // how to do this? // some code } void someClass::functionTwo() { // again some code }
Anonymous
You didn't add someClass:: for the second function definition. But you call it the right way
not asking for "someClass::" part, i told you above. asking for how to call a class function, into another function of the same class, and on normal call inside func definition it throws error: qualified name is not allowed.
Pavel
Are you sure you don't add the prefix for the declarations? Are you sure your real code looks the same way as the example?
Anonymous
Are you sure you don't add the prefix for the declarations? Are you sure your real code looks the same way as the example?
i cant send you the full code cuz the slow mode is enabled, but can dm you you for this if you want
Pavel
i cant send you the full code cuz the slow mode is enabled, but can dm you you for this if you want
This code compiles and works https://wandbox.org/permlink/JnhMxJ2skJ3M9ftu
Pavel
not for me, may i send the code for you?
No, no need to. Just check that you don't have the prefix in your function declarations inside the class. Note that in the error the compiler prints there's the line number printed where the error occured, you need to check that line.