Dima
looool
Ludovic 'Archivist'
float v; std::cout<<":>"; std::cin>>v; std::cout <<"Output " <<(v>=0f?"positive ":"negative ") <<((v==0f || v==-0f) ? "zero" : "number") <<std::endl;
Top T : Trollface Was Real
Mr
Can you write hello world ???
If i write this.. Then catch statement will run
Top T : Trollface Was Real
Ludovic 'Archivist'
does not work
It is pretty much head compiled, what doesn't work?
olli
and you need to write 0.f, otherwise i searches the literal operator f
olli
It is pretty much head compiled, what doesn't work?
the logic, since bool bar() { return -0.0f == 0.0f; }is compiled to bar(): mov eax, 1 ret https://godbolt.org/z/zHzLD_
olli
Try with > or <
bool bar(float f) { return f >= 0.0f; } bool qax() { return bar(-0.0f); } bar(float): xorps xmm1, xmm1 ucomiss xmm0, xmm1 setae al ret qax(): mov al, 1 ret it's the same
Mr
@ollirz we can use if else statement..?
Ludovic 'Archivist'
@ollirz we can use if else statement..?
Apparently you can only use binary comparisons to effectively compare 0.f and -0.f
olli
@ollirz we can use if else statement..?
yes you can, void fn(const std::string& in) { try { const int num = std::stoi(in); if (in[0] == '-') { std::cout << "negative "; } else { std::cout << "positive "; } if (num == 0) { std::cout << "zero\n"; } else { std::cout << "number\n"; } } catch (...) { std::cerr << "Invalid input\n"; } } I'd recommend getting a good book to learn programming
Oluwaseyi
Off topic... Please I need help... How do I link cell with another cell... That's if a matric number of a student is pick the next field should display name of students from the list in excel sheet.
olli
Twimc "The value representation of floating-point types is implementation-defined." http://eel.is/c++draft/basic.fundamental#8
Mr
Like this..
olli
remove it then, however error handling will be no longer present what should be print in case someone enters hello world ?
olli
Catch statement will run
not on valid inputs 5: https://onlinegdb.com/rJE9Kniv7 -0: https://onlinegdb.com/HkenY3ovX Play around on the online compiler, it does what you asked for
Mr
Mr
Check out this @ollirz
olli
Hello is no number, so its neither positive nor negative
klimi
UW dots
olli
I asked you before about the desired output in this case and got no answer.
olli
That's where I asked? What should one output in case of a non integral input?
Mr
Can i inbox u?
Anonymous
/saved
Marie
/saved
Notes in chat: - cpp - cppbook - goodgoogling - googleit - ide - learn - meta - noendl - offtopic - ot - projects
Mat
Can i inbox u?
Can you write a simple "hello world" programme?
Mat
Can you write a programme that print what you write in it?
Mr
Yup
Mr
In which language you want?
Mario
Hi all
Anonymous
hi
Mario
I want to measure the execution time of a malloc across multiple machines
Mario
Which is the best way? Rdtsc? Clock?
Mario
Thank you
Mario
:)
Ludovic 'Archivist'
I want to measure the execution time of a malloc across multiple machines
On each machine, execute malloc 10000 times and divide by 10000 the time taken, using std::chrono from C++ may help you in making that accurate enough
Ludovic 'Archivist'
Try with different sizes, I advise 8o 512o and 4096o
Ludovic 'Archivist'
It's in pure C, not C++...
You can use malloc in C++ without overhead, and gain a good way to sample time along the way
Mario
I say "malloc" but i mean any function, it's just an example
BinaryByter
I say "malloc" but i mean any function, it's just an example
Function calls cost how long it takes to switch context and change the execution poinher
Ludovic 'Archivist'
I say "malloc" but i mean any function, it's just an example
You can use any C function in C++, I don't see the issue, C++ gives far simpler and better results when benchmarking even C
Ludovic 'Archivist'
A good compiler inlines most function calls
When possible without changing meaning
Mario
My goal is to find a relation between the clock cycles needed for the function execution and the time taken based on the CPU speed. Using RDTSC i got different number of ticks for a single malloc on different machines (24 - 129).
Mario
Should malloc require same clock cycles on all CPUs?
Ludovic 'Archivist'
Malloc may even yield to another thread
Mario
Not at all
So, it depends on?
BinaryByter
So, it depends on?
Architecture, ram, current memory maps, mapping, etc etc
Ludovic 'Archivist'
So, it depends on?
CPU model, CPU instruction set, kernel, frequency of memory, eventual cache misses, virtual memory layout
Mario
Got it
Mat
U mean user input
And you can't figure the assignment?
Mario
Thank you guys...
Ludovic 'Archivist'
Got it
Example, if you do 1024 allocations of 4 bytes on Linux i386, you will have 1023 very fast allocations and one slow
olli
A good compiler inlines most function calls
It's not that easy. Inlining is not always beneficial
Mat
Whatever it is