from Benoit Lecocq with some tweaks
long double trigonometry" part workaround. caught by sthen@'s bulk build ok sthen@