Comment Comment by goldenkey A similar question, which is more apt for worthy discussion would be, is bool casting O(1), that is, constant time ?And that might differ between JITs and compiled languages and different numerical types.For any machine precision numerical types, if the code is compiled, it'll just becomeTEST EAX, EAX ...set eax to 0 or 1 based on jmp...So in most compiled languages, a bool cast on machine precision numerics, will be constant time. parent goldenkey 12 years ago
And that might differ between JITs and compiled languages and different numerical types.
For any machine precision numerical types, if the code is compiled, it'll just become
TEST EAX, EAX ...set eax to 0 or 1 based on jmp...
So in most compiled languages, a bool cast on machine precision numerics, will be constant time.