How to atomically update a maximum value?

It doesn’t seem to be possible in a single operation, but you can make a loop, that tries to do this, until it finally succeeds or value in atomic variable becomes bigger than value: template<typename T> void update_maximum(std::atomic<T>& maximum_value, T const& value) noexcept { T prev_value = maximum_value; while(prev_value < value && !maximum_value.compare_exchange_weak(prev_value, value)) {} … Read more

SQL MAX function in non-numeric columns

The functions MAX, MIN, etc. use the lexicographic order when applied to text columns. Therefore, your MAX(type) will return ‘Printer’ instead of ‘PC’ because ‘Printer’ is after (greater than) ‘PC’ in alphabetic order. Notice that in your first query the condition HAVING COUNT(distinct type) = 1 means that there can only be a single typevalue … Read more

How to increase the value of a number to the next multiple of 10, 100, 1000, 10,000 and so on

There is no need to go into the land of strings, which could be awkward if you ever had a decimal value. function RoundedMax(a) { var mx = Math.max.apply(Math, a); if (mx == 0) {return 0}; var size = Math.floor(Math.log(Math.abs(mx)) / Math.LN10); var magnitude = Math.pow(10, size); var yMax = Math.ceil(mx / magnitude) * magnitude; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)