diff --git a/compiler/builtins/bitcode/src/str.zig b/compiler/builtins/bitcode/src/str.zig index febbef5be4..74047b4995 100644 --- a/compiler/builtins/bitcode/src/str.zig +++ b/compiler/builtins/bitcode/src/str.zig @@ -310,11 +310,9 @@ const c = @cImport({ // Str.fromFloat // When we actually use this in Roc, libc will be linked so we have access to std.heap.c_allocator -pub fn strFromFloatC(int: i64) callconv(.C) RocStr { - // const foobar = @bitCast(f32, @intCast(i32, float)); - // const result = std.fmt.allocPrint(std.heap.c_allocator, "{}", .{@as(f32, foobar)}) catch unreachable; - const float = @bitCast(f64, int); - +pub fn strFromFloatC(float: f64) callconv(.C) RocStr { + // NOTE the compiled zig for float formatting seems to use LLVM11-specific features + // hopefully we can use zig instead of snprintf in the future when we upgrade var buf: [100]u8 = undefined; const result = c.snprintf(&buf, 100, "%f", float); diff --git a/compiler/gen/src/llvm/build_str.rs b/compiler/gen/src/llvm/build_str.rs index f190f83a08..ba15b095ec 100644 --- a/compiler/gen/src/llvm/build_str.rs +++ b/compiler/gen/src/llvm/build_str.rs @@ -281,11 +281,8 @@ pub fn str_from_float<'a, 'ctx, 'env>( int_symbol: Symbol, ) -> BasicValueEnum<'ctx> { let float = load_symbol(scope, &int_symbol); - let int = env - .builder - .build_bitcast(float, env.context.i64_type(), "to_bits"); - let zig_result = call_bitcode_fn(env, &[int], &bitcode::STR_FROM_FLOAT).into_struct_value(); + let zig_result = call_bitcode_fn(env, &[float], &bitcode::STR_FROM_FLOAT).into_struct_value(); zig_str_to_struct(env, zig_result).into() }