File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ var tests = []struct {
15
15
{`len({foo: 1, bar: 2})` , 2 },
16
16
{`len("hello")` , 5 },
17
17
{`abs(-5)` , 5 },
18
+ {`abs(.5)` , .5 },
18
19
{`abs(-.5)` , .5 },
19
20
{`int(5.5)` , 5 },
20
21
{`int(5)` , 5 },
Original file line number Diff line number Diff line change @@ -431,50 +431,74 @@ func Abs(x interface{}) interface{} {
431
431
case float32 :
432
432
if x .(float32 ) < 0 {
433
433
return - x .(float32 )
434
+ } else {
435
+ return x
434
436
}
435
437
case float64 :
436
438
if x .(float64 ) < 0 {
437
439
return - x .(float64 )
440
+ } else {
441
+ return x
438
442
}
439
443
case int :
440
444
if x .(int ) < 0 {
441
445
return - x .(int )
446
+ } else {
447
+ return x
442
448
}
443
449
case int8 :
444
450
if x .(int8 ) < 0 {
445
451
return - x .(int8 )
452
+ } else {
453
+ return x
446
454
}
447
455
case int16 :
448
456
if x .(int16 ) < 0 {
449
457
return - x .(int16 )
458
+ } else {
459
+ return x
450
460
}
451
461
case int32 :
452
462
if x .(int32 ) < 0 {
453
463
return - x .(int32 )
464
+ } else {
465
+ return x
454
466
}
455
467
case int64 :
456
468
if x .(int64 ) < 0 {
457
469
return - x .(int64 )
470
+ } else {
471
+ return x
458
472
}
459
473
case uint :
460
474
if x .(uint ) < 0 {
461
475
return - x .(uint )
476
+ } else {
477
+ return x
462
478
}
463
479
case uint8 :
464
480
if x .(uint8 ) < 0 {
465
481
return - x .(uint8 )
482
+ } else {
483
+ return x
466
484
}
467
485
case uint16 :
468
486
if x .(uint16 ) < 0 {
469
487
return - x .(uint16 )
488
+ } else {
489
+ return x
470
490
}
471
491
case uint32 :
472
492
if x .(uint32 ) < 0 {
473
493
return - x .(uint32 )
494
+ } else {
495
+ return x
474
496
}
475
497
case uint64 :
476
498
if x .(uint64 ) < 0 {
477
499
return - x .(uint64 )
500
+ } else {
501
+ return x
478
502
}
479
503
}
480
504
panic (fmt .Sprintf ("invalid argument for abs (type %T)" , x ))
You can’t perform that action at this time.
0 commit comments