public static Stella_Object coerceIncompatibleValue(Stella_Object value, Surrogate type) {
    { Stella_Object substituteValue = null;

      if (Logic.relationrefSpecializesRelationrefP(type, Logic.SGT_PL_KERNEL_KB_QUANTITY)) {
        return (Logic.coerceQuantity(value, type));
      }
      else if (Logic.relationrefSpecializesRelationrefP(type, Logic.SGT_PL_KERNEL_KB_DATE)) {
        return (Logic.coerceDate(value, type));
      }
      else if (Stella_Object.isaP(value, Logic.SGT_STELLA_LITERAL_WRAPPER) &&
          Logic.testIsaP(Logic.rewrapArgument(value), type)) {
        return (Logic.rewrapArgument(value));
      }
      { Surrogate testValue000 = Stella_Object.safePrimaryType(value);

        if (Surrogate.subtypeOfIntegerP(testValue000)) {
          { IntegerWrapper value000 = ((IntegerWrapper)(value));

            if (type == Logic.SGT_STELLA_FLOAT) {
              { int intvalue = value000.wrapperValue;
                double floatvalue = ((double)(intvalue));

                substituteValue = FloatWrapper.wrapFloat(floatvalue);
              }
            }
          }
        }
        else if (Surrogate.subtypeOfFloatP(testValue000)) {
          { FloatWrapper value000 = ((FloatWrapper)(value));

            if (type == Logic.SGT_STELLA_INTEGER) {
              { double floatvalue = value000.wrapperValue;
                int intvalue = Native.floor(floatvalue);

                if (((double)(intvalue)) == floatvalue) {
                  substituteValue = IntegerWrapper.wrapInteger(intvalue);
                }
              }
            }
          }
        }
        else {
        }
      }
      return (substituteValue);
    }
  }