Cherry-pick changes to std.math into 2.066

2 bug fixes
1 documentation fix

Rest is enhancements, mostly in coding style.