Harmonise behaviour with reference code

Still missing on Idamax, but that may require some more thinking.