getObservedIndividuals

getObservedIndividuals

我正在尝试从此double部门返回一个int。我读了this question,但我似乎无法使其适用于这种特殊情况:

yComponent +=
        ((Math.min(i.getObservedIndividuals(), ii.getObservedIndividuals()))/
        Math.max(i.getObservedIndividuals(), ii.getObservedIndividuals())*
        i.getObservedIndividuals())/
        (parent.getShareableSpecies()*
        match.getTotalObservedIndividuals());


yComponentdouble,其他所有内容都是int

最佳答案

yComponent +=
    ((Math.min(i.getObservedIndividuals(), ii.getObservedIndividuals())) /
    (double) Math.max(i.getObservedIndividuals(), ii.getObservedIndividuals())*
    i.getObservedIndividuals()) /
    (double) (parent.getShareableSpecies()*
    match.getTotalObservedIndividuals());


如果您没有将至少一个操作数转换为double或float,则除法将不会使用“ float处理器”(算术处理器)。这表示3 / 2 = 1用于CPU,但3 / 2f = 1.5f

08-16 02:35