how can I make this expression not end up being a zero.
double dBaseFitness = (double) baseFitness;
x.shortfitness = (long)(Math.pow(dbaseFitness, dbaseFitness/8开发者_开发技巧.0)/100.0)
*(long)(Math.pow((double)x.genome.GSIZE, -.1)/100.0);
x.shortfitness is a long value. x.Genome.GSIZE is an int.
The only reason I am dividing each expression by 100 is so that the result doesn't exceed the max value of the long type.
Is baseFitness
an integer? If so then baseFitness/8
does integer division. For example 7/8
will yield 0
. Change your 8
and 100
to 8d
and 100d
to force floating point division.
If both the operands of an arithmetic expression are integral types, then the result will be too. So, for example, if "baseFitness" is an integer less than 8, then baseFitness/8 will be zero. Use "8.0" and "100.0" instead.
精彩评论