segfault using c++ math functions on long double

44 views
Skip to first unread message

hebe...@gmail.com

unread,
Apr 19, 2016, 11:58:05 AM4/19/16
to mingwpy
Hi,

I noticed that using c++ math functions, e.g. std::fmod on long doubles result in a segfault when compiled with the current pip-installed mingwpy version (gcc version 4.9.2 (x86_64-win32-seh-rev201506, mingwpy build)).
See sample function below.

Cheers,
Edwin


#include <cstdio>
#include <cmath>

int main()
{
    printf("fmod -> %f\n", fmod((long double)1, 16));
    printf("std::fmod -> %f\n", std::fmod((long double)1, 16));
    return 0;
}

carlkl

unread,
Apr 19, 2016, 2:19:55 PM4/19/16
to mingwpy, hebe...@gmail.com
Hi,

mingwpy is trimmed to use long doubles as doubles per default as this is the default for MSVC.

If you need extended precision you have to add the -mlong-double=80 flag to the command line and add the CRT_fp10.o object to the link line. This should be documented in the mingwpy documentation.

Unfortunately for this mingwpy version (gcc-4.9.2) the mlong-double=64 flag is hardcoded in the compiler specs, I'm not sure if it helps if you add -mlong-double=80 to the compiler flags; please try this out.

The next version of mingwpy will work as expected.

Carl

hebe...@gmail.com

unread,
Apr 19, 2016, 3:51:41 PM4/19/16
to mingwpy
Hi Carl,

I don't really need 80 bit precision, but I'm compiling VXL, part of ITK, which uses long doubles. Mingwpy's default settings, resulting in msvc-compatible libraries are fine.

Are these segfaults to be expected? Or is it a bug?

How should I prevent these segfaults from happening while using mingwpy's default setting, i.e. 64 bit long doubles?

Edwin

Nathaniel Smith

unread,
Apr 19, 2016, 5:48:48 PM4/19/16
to mingwpy
Maybe the problem is that libstdc++ is getting compiled with
-mlong-double=80, and that has ABI effects that make it incompatible
with code compiled with -mlong-double=64? Is mingwpy's tweak of the
spec file defaults happening before or after libstdc++ gets built?

-n
> --
> You received this message because you are subscribed to the Google Groups "mingwpy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mingwpy+u...@googlegroups.com.
> To post to this group, send email to min...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mingwpy/9f461159-ef92-4411-91b6-3a12b0b8b320%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Nathaniel J. Smith -- https://vorpus.org

carlkl

unread,
Apr 21, 2016, 3:31:10 AM4/21/16
to mingwpy
Obviously libstdc++  should work, regardless the choosen long double setting during compile time. I guess this has to be fixed in the mingw-w64 math code.

Edwin, can you issue this problem on github: https://github.com/mingwpy/mingwpy/issues ?

Carl


Am Dienstag, 19. April 2016 23:48:48 UTC+2 schrieb Nathaniel Smith:
Maybe the problem is that libstdc++ is getting compiled with
-mlong-double=80, and that has ABI effects that make it incompatible
with code compiled with -mlong-double=64? Is mingwpy's tweak of the
spec file defaults happening before or after libstdc++ gets built?

-n

On Tue, Apr 19, 2016 at 12:51 PM,  <hebe...@gmail.com> wrote:
> Hi Carl,
>
> I don't really need 80 bit precision, but I'm compiling VXL, part of ITK, which uses long doubles. Mingwpy's default settings, resulting in msvc-compatible libraries are fine.
>
> Are these segfaults to be expected? Or is it a bug?
>
> How should I prevent these segfaults from happening while using mingwpy's default setting, i.e. 64 bit long doubles?
>
> Edwin
>
> --
> You received this message because you are subscribed to the Google Groups "mingwpy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mingwpy+unsubscribe@googlegroups.com.

hebe...@gmail.com

unread,
Apr 21, 2016, 8:49:26 AM4/21/16
to mingwpy
Sure, just did it!


On Thursday, April 21, 2016 at 9:31:10 AM UTC+2, carlkl wrote:
Obviously libstdc++  should work, regardless the choosen long double setting during compile time. I guess this has to be fixed in the mingw-w64 math code.

Edwin, can you issue this problem on github: https://github.com/mingwpy/mingwpy/issues ?

Carl

Am Dienstag, 19. April 2016 23:48:48 UTC+2 schrieb Nathaniel Smith:
Maybe the problem is that libstdc++ is getting compiled with
-mlong-double=80, and that has ABI effects that make it incompatible
with code compiled with -mlong-double=64? Is mingwpy's tweak of the
spec file defaults happening before or after libstdc++ gets built?

-n

On Tue, Apr 19, 2016 at 12:51 PM,  <hebe...@gmail.com> wrote:
> Hi Carl,
>
> I don't really need 80 bit precision, but I'm compiling VXL, part of ITK, which uses long doubles. Mingwpy's default settings, resulting in msvc-compatible libraries are fine.
>
> Are these segfaults to be expected? Or is it a bug?
>
> How should I prevent these segfaults from happening while using mingwpy's default setting, i.e. 64 bit long doubles?
>
> Edwin
>
> --
> You received this message because you are subscribed to the Google Groups "mingwpy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mingwpy+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages