Skip to content

Floating point values are truncated when run on M1 with Rosetta x86_64 emulation (via Docker) #19677

@RobinMalfait

Description

@RobinMalfait

What version of Bun is running?

1.2.13+64ed68c9e

What platform is your computer?

Darwin 24.4.0 arm64 arm

What steps can reproduce the bug?

If you run the following script, then the first docker run which uses linux/x86_64 will produce truncated values. Only on M1, running this on an M4 does work as expected.

The second docker run which uses linux/arm64 also works as expected.

#!/usr/bin/env bash

cat > repro.sh <<EOF
#!/usr/bin/env bash

curl -fsSL https://bun.sh/install | bash

~/.bun/bin/bun --print '[0.25, Number("0.25")]'
EOF

chmod +x repro.sh

# [ 0, 0 ]
docker run --mount=type=bind,source=$(pwd),target=/repro -w /repro --platform=linux/x86_64 node:24 ./repro.sh

# [ 0.25, 0.25 ]
docker run --mount=type=bind,source=$(pwd),target=/repro -w /repro --platform=linux/arm64 node:24 ./repro.sh

Running the same setup using node, then it works in both cases:

#!/usr/bin/env bash

cat > repro.sh <<EOF
#!/usr/bin/env bash

node -e 'console.log([0.25, Number("0.25")])'
EOF

chmod +x repro.sh

# [ 0.25, 0.25 ]
docker run --mount=type=bind,source=$(pwd),target=/repro -w /repro --platform=linux/x86_64 node:24 ./repro.sh

# [ 0.25, 0.25 ]
docker run --mount=type=bind,source=$(pwd),target=/repro -w /repro --platform=linux/arm64 node:24 ./repro.sh

What is the expected behavior?

When using floating point numbers such as 0.25 or 1.25 I expect them to to stay as-is, instead of being truncated to just 0 and 1 respectively.

What do you see instead?

Floating point numbers such as 0.25 and 1.25 get truncated to just 0 and 1 respectively.

Additional information

It also looks like this behavior happens in cases such as:

Number('1.25')      // 1
parseFloat('1.25')  // 1
1 / 4               // 0

Other fun observation:

In Docker Desktop, if you uncheck the Use Rosetta for x86_64/amd64 emulation on Apple Silicon option, or switch to Docker VMM or switch to QEMU (Legacy) then it will work as expected.

But the moment you use Apple Virtualization framework with the Use Rosetta for x86_64/amd64 emulation on Apple Silicon checked, then it will fail.

Image

Edit: also tested this on an M1 Mac mini and it also reproduces there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream:applerelated to an issue in Apple software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions