File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ var tests = []struct {
1515 {`len({foo: 1, bar: 2})` , 2 },
1616 {`len("hello")` , 5 },
1717 {`abs(-5)` , 5 },
18+ {`abs(.5)` , .5 },
1819 {`abs(-.5)` , .5 },
1920 {`int(5.5)` , 5 },
2021 {`int(5)` , 5 },
Original file line number Diff line number Diff line change @@ -431,50 +431,74 @@ func Abs(x interface{}) interface{} {
431431 case float32 :
432432 if x .(float32 ) < 0 {
433433 return - x .(float32 )
434+ } else {
435+ return x
434436 }
435437 case float64 :
436438 if x .(float64 ) < 0 {
437439 return - x .(float64 )
440+ } else {
441+ return x
438442 }
439443 case int :
440444 if x .(int ) < 0 {
441445 return - x .(int )
446+ } else {
447+ return x
442448 }
443449 case int8 :
444450 if x .(int8 ) < 0 {
445451 return - x .(int8 )
452+ } else {
453+ return x
446454 }
447455 case int16 :
448456 if x .(int16 ) < 0 {
449457 return - x .(int16 )
458+ } else {
459+ return x
450460 }
451461 case int32 :
452462 if x .(int32 ) < 0 {
453463 return - x .(int32 )
464+ } else {
465+ return x
454466 }
455467 case int64 :
456468 if x .(int64 ) < 0 {
457469 return - x .(int64 )
470+ } else {
471+ return x
458472 }
459473 case uint :
460474 if x .(uint ) < 0 {
461475 return - x .(uint )
476+ } else {
477+ return x
462478 }
463479 case uint8 :
464480 if x .(uint8 ) < 0 {
465481 return - x .(uint8 )
482+ } else {
483+ return x
466484 }
467485 case uint16 :
468486 if x .(uint16 ) < 0 {
469487 return - x .(uint16 )
488+ } else {
489+ return x
470490 }
471491 case uint32 :
472492 if x .(uint32 ) < 0 {
473493 return - x .(uint32 )
494+ } else {
495+ return x
474496 }
475497 case uint64 :
476498 if x .(uint64 ) < 0 {
477499 return - x .(uint64 )
500+ } else {
501+ return x
478502 }
479503 }
480504 panic (fmt .Sprintf ("invalid argument for abs (type %T)" , x ))
You can’t perform that action at this time.
0 commit comments