[Issue 23846] std.math can't compile under macos rosetta

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 23 11:55:40 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23846

--- Comment #3 from Caleb Xu <calebcenter at live.com> ---
(In reply to kinke from comment #2)
> Thanks for this insight. DMD uses the C runtime's `strto{f,d}` to check for
> over/underflows of float/double literals (in
> `Port.isFloat{32,64}LiteralOutOfRange()`). So an Apple libc change might
> indeed be the culprit. - LDC isn't affected, it uses LLVM functionality to
> parse floating-point literals.

Thanks for the tip. I tried this simple C program (based on strto{d,f}
invocations from [1], [2]) on a machine with the new Xcode and it outputs four
"true"s as expected. So far this seems to work, at least as far as not throwing
an error when parsing the strings into float/double:

#include <stdio.h>
#include <stdlib.h>

int main() {
    float float1 = strtof("0x0.8p-126f", NULL);
    printf("%s\n", (float1 != 0) ? "true" : "false");

    float float2 = strtof("0x0.555556p-126f", NULL);
    printf("%s\n", (float2 != 0) ? "true" : "false");

    double double1 = strtod("0x0.8p-1022", NULL);
    printf("%s\n", (double1 != 0) ? "true" : "false");

    double double2 = strtod("0x0.5555555555555p-1022", NULL);
    printf("%s\n", (double2 != 0) ? "true" : "false");
}

[1]:
https://github.com/dlang/dmd/blob/34c57751f8f50f623740387599f02c4ace34ee6a/compiler/src/dmd/root/port.d#L91
[2]:
https://github.com/dlang/dmd/blob/34c57751f8f50f623740387599f02c4ace34ee6a/compiler/src/dmd/root/port.d#L114

--


More information about the Digitalmars-d-bugs mailing list