Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
を計算しようとしています。a^(1/n)ここで、^べき乗を示します。
a^(1/n)
^
ただし、次のとおりです。
Math.pow(8, 1/3)
を返す1.0代わりに を返し2.0ます。
1.0
2.0
何故ですか?
1/3となります0( 1and3はintリテラルとして扱われるため)。
1/3
0
1
3
int
したがって、これらのリテラルを float/double にする必要があります...
行う:
Math.pow(8, 1f/3) また
Math.pow(8, 1f/3)
Math.pow(8, 1./3) また
Math.pow(8, 1./3)
Math.pow(8, 1.0/3)
Math.pow(8, (1.0f / 3.0f))代わりに試してください。
Math.pow(8, (1.0f / 3.0f))
1 / 3整数除算を行います。これにより、8 ^ 0 = 1
1 / 3
8 ^ 0 = 1