void test_rounding(void) {
  float fp1, fp2;
  double df1, df2;
  fp1 = exp(1.1);
  printf(" exp(1.1) = %+0.8f\n", fp1);
  fp2 = -exp(1.1);
  printf("-exp(1.1) = %+0.8f\n", fp2);
  df1 = exp(1.1);
  df2 = -exp(1.1);
  printf(" double exp(1.1) = %+0.8lf\n", df1);
  printf("-double exp(1.1) = %+0.8lf\n", df2);
}


x86 assembly (clang, -O0):
<test_rounding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0xed0(%rip),%xmm0
call   1040 <exp@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xeba(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xea3(%rip),%xmm0
call   1040 <exp@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xe5f(%rip),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xe4d(%rip),%xmm0
call   1040 <exp@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe50(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe59(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rounding>:
push   %rax
lea    0xf08(%rip),%rdi
movsd  0xee0(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
movsd  0xed2(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
movsd  0xec4(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
movsd  0xeb6(%rip),%xmm0
mov    $0x1,%al
pop    %rcx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c" exp(1.1) = %+0.8f\0A\00"
@.str.1 = [20 x i8] c"-exp(1.1) = %+0.8f\0A\00"
@.str.2 = [28 x i8] c" double exp(1.1) = %+0.8lf\0A\00"
@.str.3 = [28 x i8] c"-double exp(1.1) = %+0.8lf\0A\00"
define void @test_rounding() {
%1 = alloca float
%2 = alloca float
%3 = alloca double
%4 = alloca double
%5 = call double @exp(double 1.100000e+00)
%6 = fptrunc double %5 to float
store float %6, float* %1
%7 = load float, float* %1
%8 = fpext float %7 to double
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %8)
%10 = call double @exp(double 1.100000e+00)
%11 = fneg double %10
%12 = fptrunc double %11 to float
store float %12, float* %2
%13 = load float, float* %2
%14 = fpext float %13 to double
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %14)
%16 = call double @exp(double 1.100000e+00)
store double %16, double* %3
%17 = call double @exp(double 1.100000e+00)
%18 = fneg double %17
store double %18, double* %4
%19 = load double, double* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = load double, double* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %21)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c" exp(1.1) = %+0.8f\0A\00"
@.str.1 = [20 x i8] c"-exp(1.1) = %+0.8f\0A\00"
@.str.2 = [28 x i8] c" double exp(1.1) = %+0.8lf\0A\00"
@.str.3 = [28 x i8] c"-double exp(1.1) = %+0.8lf\0A\00"
define void @test_rounding() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double 0x4008088840000000)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double 0xC008088840000000)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double 0x400808883244D593)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double 0xC00808883244D593)
ret void
}