MCPcopy Create free account
hub / github.com/beanshell/beanshell / promotePrimitives

Method promotePrimitives

src/bsh/Primitive.java:610–646  ·  view source on GitHub ↗

Promote the pair of primitives to the maximum type of the two. e.g. [int,long]->[long,long]

(Object lhs, Object rhs)

Source from the content-addressed store, hash-verified

608 e.g. [int,long]->[long,long]
609 */
610 static Object[] promotePrimitives(Object lhs, Object rhs)
611 {
612 lhs = promoteToInteger(lhs);
613 rhs = promoteToInteger(rhs);
614
615 if((lhs instanceof Number) && (rhs instanceof Number))
616 {
617 Number lnum = (Number)lhs;
618 Number rnum = (Number)rhs;
619
620 boolean b;
621
622 if((b = (lnum instanceof Double)) || (rnum instanceof Double))
623 {
624 if(b)
625 rhs = new Double(rnum.doubleValue());
626 else
627 lhs = new Double(lnum.doubleValue());
628 }
629 else if((b = (lnum instanceof Float)) || (rnum instanceof Float))
630 {
631 if(b)
632 rhs = new Float(rnum.floatValue());
633 else
634 lhs = new Float(lnum.floatValue());
635 }
636 else if((b = (lnum instanceof Long)) || (rnum instanceof Long))
637 {
638 if(b)
639 rhs = new Long(rnum.longValue());
640 else
641 lhs = new Long(lnum.longValue());
642 }
643 }
644
645 return new Object[] { lhs, rhs };
646 }
647
648 public static Primitive unaryOperation(Primitive val, int kind)
649 throws UtilEvalError

Callers 1

binaryOperationMethod · 0.95

Calls 1

promoteToIntegerMethod · 0.95

Tested by

no test coverage detected