Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@cImport Fails with gmp_sprintf for mpfr_t Variadic Args #23009

Open
fmozza opened this issue Feb 25, 2025 · 0 comments
Open

@cImport Fails with gmp_sprintf for mpfr_t Variadic Args #23009

fmozza opened this issue Feb 25, 2025 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)

Comments

@fmozza
Copy link

fmozza commented Feb 25, 2025

Zig Version

0.14.0-dev.3222+8a3aebaee:

Steps to Reproduce and Observed Behavior

Description

In Zig 0.14.0, gmp_sprintf via @cImport fails to format mpfr_t arguments (from MPC) with %Rf, outputting the format string (%Rf, 3 chars) instead of the value. It works correctly with mpf_t (GMP) and %Ff.

Steps to Reproduce

  1. Install Zig 0.14.0, libgmp-dev, libmpfr-dev, libmpc-dev on Ubuntu.
  2. Use the attached demo.zig and build.zig.
  3. Run zig build run --verbose.

Observed Behavior

mpf_t: 3.141589999999999882618340052431449294090270996093, wrote: 52 mpfr_t: %Rf, wrote: 3

  • mpf_t works as expected.
  • mpfr_t outputs %Rf instead of the value.

Environment

  • Zig: 0.14.0
  • OS: Ubuntu 24.04
  • GMP: 6.3.0
  • MPFR: 4.2.1
  • MPC: 1.3.1

Expected Behavior

Expected Behavior

  • mpf_t: Formats as 3.14159... (GMP float).
  • mpfr_t: Formats as 2.718... (MPFR float from MPC).

bug_demo.zip

@fmozza fmozza added the bug Observed behavior contradicts documented or intended behavior label Feb 25, 2025
@alexrp alexrp added the translate-c C to Zig source translation feature (@cImport) label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

2 participants