@@ -2367,6 +2367,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
2367
2367
@ast. expr e, & ast. ann a) -> result {
2368
2368
2369
2369
auto sub = trans_expr( cx, e) ;
2370
+ auto e_ty = ty. expr_ty( e) ;
2370
2371
2371
2372
alt ( op) {
2372
2373
case ( ast. bitnot) {
@@ -2379,7 +2380,12 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
2379
2380
}
2380
2381
case ( ast. neg) {
2381
2382
sub = autoderef( sub. bcx, sub. val, ty. expr_ty( e) ) ;
2382
- ret res( sub. bcx, sub. bcx. build. Neg ( sub. val) ) ;
2383
+ if ( e_ty. struct == ty. ty_float) {
2384
+ ret res( sub. bcx, sub. bcx. build. FNeg ( sub. val) ) ;
2385
+ }
2386
+ else {
2387
+ ret res( sub. bcx, sub. bcx. build. Neg ( sub. val) ) ;
2388
+ }
2383
2389
}
2384
2390
case ( ast. box) {
2385
2391
auto e_ty = ty. expr_ty( e) ;
@@ -2674,24 +2680,60 @@ fn trans_vec_add(@block_ctxt cx, @ty.t t,
2674
2680
fn trans_eager_binop( @block_ctxt cx, ast. binop op, @ty. t intype,
2675
2681
ValueRef lhs, ValueRef rhs) -> result {
2676
2682
2683
+ auto is_float = false;
2684
+ alt( intype. struct ) {
2685
+ case ( ty. ty_float) {
2686
+ is_float = true;
2687
+ }
2688
+ case ( _) {
2689
+ is_float = false;
2690
+ }
2691
+ }
2692
+
2677
2693
alt ( op) {
2678
2694
case ( ast. add) {
2679
2695
if ( ty. type_is_sequence( intype) ) {
2680
2696
ret trans_vec_add( cx, intype, lhs, rhs) ;
2681
2697
}
2682
- ret res( cx, cx. build. Add ( lhs, rhs) ) ;
2698
+ if ( is_float) {
2699
+ ret res( cx, cx. build. FAdd ( lhs, rhs) ) ;
2700
+ }
2701
+ else {
2702
+ ret res( cx, cx. build. Add ( lhs, rhs) ) ;
2703
+ }
2704
+ }
2705
+ case ( ast. sub) {
2706
+ if ( is_float) {
2707
+ ret res( cx, cx. build. FSub ( lhs, rhs) ) ;
2708
+ }
2709
+ else {
2710
+ ret res( cx, cx. build. Sub ( lhs, rhs) ) ;
2711
+ }
2712
+ }
2713
+
2714
+ case ( ast. mul) {
2715
+ if ( is_float) {
2716
+ ret res( cx, cx. build. FMul ( lhs, rhs) ) ;
2717
+ }
2718
+ else {
2719
+ ret res( cx, cx. build. Mul ( lhs, rhs) ) ;
2720
+ }
2683
2721
}
2684
- case ( ast. sub) { ret res( cx, cx. build. Sub ( lhs, rhs) ) ; }
2685
2722
2686
- case ( ast. mul) { ret res( cx, cx. build. Mul ( lhs, rhs) ) ; }
2687
2723
case ( ast. div) {
2724
+ if ( is_float) {
2725
+ ret res( cx, cx. build. FDiv ( lhs, rhs) ) ;
2726
+ }
2688
2727
if ( ty. type_is_signed( intype) ) {
2689
2728
ret res( cx, cx. build. SDiv ( lhs, rhs) ) ;
2690
2729
} else {
2691
2730
ret res( cx, cx. build. UDiv ( lhs, rhs) ) ;
2692
2731
}
2693
2732
}
2694
2733
case ( ast. rem) {
2734
+ if ( is_float) {
2735
+ ret res( cx, cx. build. FRem ( lhs, rhs) ) ;
2736
+ }
2695
2737
if ( ty. type_is_signed( intype) ) {
2696
2738
ret res( cx, cx. build. SRem ( lhs, rhs) ) ;
2697
2739
} else {
0 commit comments