stainless-steel / special

Special functions
Other
10 stars 16 forks source link

Fixing link error on lgamma_r on windows #4

Closed albertp007 closed 8 years ago

albertp007 commented 8 years ago

Hello, greetings. This is to fix the link error that happens on Windows where lgamma_r() does not exist. The equivalent in MSVC is actually called lgamma() with the sign output parameter (whereas in GNU, lgamma doesn't have a sign output parameter)

I added conditonal compile configs in m.rs to link lgamma on windows and lgamma_r on unix. Also, for windows, I created a lgamma_r function which simply delegates to lgamma. This is so that the rest of the code can assume the existence of lgamma_r.

However, the cons is, it will cause a warning "unnecessary unsafe" in gamma.rs. This is because I need to add an unsafe block in the "faked" lgamma_r for calling lgamma.

To fix that, I simply created a conditional compile in gamma.rs for ln_gamma() to call lgamma_r on unix and lgamma on windows. Assuming ln_gamma() is now the wrapper, there is no point to fake lgamma_r() in m.rs, hence removed in the second commit.

The tests all passed on both Mac OSX and Windows 10.

Please kindly review and let me know if you have any questions/comments.

Cheers, Albert

IvanUkhov commented 8 years ago

Thanks a lot for the help!