unsigned short float_to_fract1_1_14(double val) {
  unsigned short fract;
  unsigned long long llval;
  if (val < 0.000000) {
    fract = 0x8000;
    val *= -1.0;
  } else {
    fract = 0;
  }
  if (val >= 2.0)
    val = 1.999999;
  val *= 1000000;
  llval = (unsigned long long)val * 0x4000UL;
  fract |= (llval / 1000000);
  return fract;
}


x86 assembly (clang, -O0):
<float_to_fract1_1_14>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1134 <float_to_fract1_1_14+0x34>
movw   $0x8000,-0xa(%rbp)
movsd  0xedb(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    113a <float_to_fract1_1_14+0x3a>
movw   $0x0,-0xa(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xec1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     115e <float_to_fract1_1_14+0x5e>
movsd  0xeb7(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
shl    $0xe,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
movzwl -0xa(%rbp),%eax
or     %rcx,%rax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_to_fract1_1_14>:
xorpd  %xmm1,%xmm1
xor    %ecx,%ecx
ucomisd %xmm0,%xmm1
seta   %sil
jbe    1118 <float_to_fract1_1_14+0x18>
xorpd  0xee8(%rip),%xmm0
movsd  0xef0(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xeec(%rip),%xmm2
cmpnlesd %xmm0,%xmm2
andpd  %xmm2,%xmm1
movsd  0xee3(%rip),%xmm0
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
cvttsd2si %xmm2,%rdx
mov    %rdx,%rdi
sar    $0x3f,%rdi
subsd  0xecf(%rip),%xmm2
cvttsd2si %xmm2,%rax
and    %rdi,%rax
or     %rdx,%rax
shl    $0xe,%rax
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mul    %rdx
shr    $0x12,%rdx
mov    %sil,%cl
shl    $0xf,%ecx
or     %edx,%ecx
mov    %ecx,%eax
ret

LLVM IR (-O0):
define zeroext i16 @float_to_fract1_1_14(double %0) {
%2 = alloca double
%3 = alloca i16
%4 = alloca i64
store double %0, double* %2
%5 = load double, double* %2
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %7, label %10
7: ; preds = %1
store i16 -32768, i16* %3
%8 = load double, double* %2
%9 = fmul double %8, -1.000000e+00
store double %9, double* %2
br label %11
10: ; preds = %1
store i16 0, i16* %3
br label %11
11: ; preds = %10, %7
%12 = load double, double* %2
%13 = fcmp oge double %12, 2.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11
store double 0x3FFFFFFEF39085F5, double* %2
br label %15
15: ; preds = %14, %11
%16 = load double, double* %2
%17 = fmul double %16, 1.000000e+06
store double %17, double* %2
%18 = load double, double* %2
%19 = fptoui double %18 to i64
%20 = mul i64 %19, 16384
store i64 %20, i64* %4
%21 = load i64, i64* %4
%22 = udiv i64 %21, 1000000
%23 = load i16, i16* %3
%24 = zext i16 %23 to i64
%25 = or i64 %24, %22
%26 = trunc i64 %25 to i16
store i16 %26, i16* %3
%27 = load i16, i16* %3
ret i16 %27
}

LLVM IR (-O2):
define zeroext i16 @float_to_fract1_1_14(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, i64 32768, i64 0
%5 = select i1 %2, double %3, double %0
%6 = fcmp ult double %5, 2.000000e+00
%7 = fmul double %5, 1.000000e+06
%8 = select i1 %6, double %7, double 0x413E847F00000000
%9 = fptoui double %8 to i64
%10 = shl i64 %9, 14
%11 = udiv i64 %10, 1000000
%12 = or i64 %11, %4
%13 = trunc i64 %12 to i16
ret i16 %13
}