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

Saner behavior in rb_gsl_complex_printf. #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions ext/gsl_native/complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ static VALUE rb_gsl_complex_print(VALUE obj)
static VALUE rb_gsl_complex_printf(VALUE obj, VALUE s)
{
gsl_complex *c = NULL;
char tmp[32], format[64];
VALUE format, out;
VALUE vals[2];
Check_Type(s, T_STRING);
Data_Get_Struct(obj, gsl_complex, c);
strcpy(tmp, STR2CSTR(s));
sprintf(format, "%s %s\n", tmp, tmp);
fprintf(stdout, format, GSL_REAL(*c), GSL_IMAG(*c));

vals[0] = rb_float_new(GSL_REAL(*c));
vals[1] = rb_float_new(GSL_IMAG(*c));
format = rb_sprintf("%s %s\n", STR2CSTR(s), STR2CSTR(s));
RB_GC_GUARD(s);
out = rb_str_format(2, vals, format);
fwrite(StringValuePtr(out), 1, RSTRING_LEN(out), stdout);
return obj;
}

Expand Down