質問するログイン新規登録

回答編集履歴

5

修正

2021/04/21 07:27

投稿

退会済みユーザー
answer CHANGED
@@ -38,4 +38,5 @@
38
38
  i=189
39
39
  j=11
40
40
  366461620334848584
41
+ 366461620334848584
41
42
  ```

4

リンク追加

2021/04/21 07:27

投稿

退会済みユーザー
answer CHANGED
@@ -1,5 +1,5 @@
1
1
  VB.NETの整数除算は \ です。
2
- / で除算した場合はオペランドの型によって結果の型が違いますが、今回の場合はDoubleになります。Double型の有効桁数は15桁なので、それをLongを戻した際に誤差が発生します。
2
+ / で除算した場合はオペランドのデータ型によって結果のデータ型が違いますが、今回の場合はDoubleになります。([/ 演算子](https://docs.microsoft.com/ja-jp/dotnet/visual-basic/language-reference/operators/floating-point-division-operator)の説明を参照してください。) Double型の有効桁数は15桁なので、それをLongを戻した際に誤差が発生します。
3
3
 
4
4
  [Visual Basic における算術演算子](https://docs.microsoft.com/ja-jp/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/arithmetic-operators)
5
5
 

3

修正

2021/04/21 07:15

投稿

退会済みユーザー
answer CHANGED
@@ -1,5 +1,5 @@
1
1
  VB.NETの整数除算は \ です。
2
- / で除算した場合はDoubleなりDouble型の有効桁数は15桁なので、それをLongを戻した際に誤差が発生します。
2
+ / で除算した場合はオペランドのによって結果の型が違いますが、今回の場合はDoubleになります。Double型の有効桁数は15桁なので、それをLongを戻した際に誤差が発生します。
3
3
 
4
4
  [Visual Basic における算術演算子](https://docs.microsoft.com/ja-jp/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/arithmetic-operators)
5
5
 

2

追記

2021/04/21 07:12

投稿

退会済みユーザー
answer CHANGED
@@ -1,4 +1,41 @@
1
1
  VB.NETの整数除算は \ です。
2
2
  / で除算した場合はDouble型となり、Double型の有効桁数は15桁なので、それをLongを戻した際に誤差が発生します。
3
3
 
4
- [Visual Basic における算術演算子](https://docs.microsoft.com/ja-jp/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/arithmetic-operators)
4
+ [Visual Basic における算術演算子](https://docs.microsoft.com/ja-jp/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/arithmetic-operators)
5
+
6
+ 提示されたサンプルコードの /= している箇所を \= にして実行すると、結果は下記のようになります。
7
+ ```
8
+ i=199
9
+ j=1
10
+ 199
11
+ i=198
12
+ j=2
13
+ 19701
14
+ i=197
15
+ j=3
16
+ 1293699
17
+ i=196
18
+ j=4
19
+ 63391251
20
+ i=195
21
+ j=5
22
+ 2472258789
23
+ i=194
24
+ j=6
25
+ 79936367511
26
+ i=193
27
+ j=7
28
+ 2203959847089
29
+ i=192
30
+ j=8
31
+ 52895036330136
32
+ i=191
33
+ j=9
34
+ 1122550215450664
35
+ i=190
36
+ j=10
37
+ 21328454093562616
38
+ i=189
39
+ j=11
40
+ 366461620334848584
41
+ ```

1

修正

2021/04/21 07:08

投稿

退会済みユーザー
answer CHANGED
@@ -1,4 +1,4 @@
1
1
  VB.NETの整数除算は \ です。
2
- / で除算した場合はDouble型となり、Double型の有効桁数は15桁ので誤差が発生します。
2
+ / で除算した場合はDouble型となり、Double型の有効桁数は15桁なので、それをLongを戻した際に誤差が発生します。
3
3
 
4
4
  [Visual Basic における算術演算子](https://docs.microsoft.com/ja-jp/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/arithmetic-operators)