АндрейАкиньшин,jetbrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf ·...
TRANSCRIPT
![Page 1: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/1.jpg)
Поговорим про арифметику
Андрей Акиньшин, JetBrains
DotNext 2016 SPb
1/32
![Page 2: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/2.jpg)
Про что будем разговаривать?
2/32
![Page 3: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/3.jpg)
Упражнение №1
Задача. Что выведет следующий код?Write(0.1 + 0.2 == 0.3);
A true
X
B
B
false
C 0.3
D ArithmeticException
3/32
![Page 4: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/4.jpg)
Упражнение №1
Задача. Что выведет следующий код?Write(0.1 + 0.2 == 0.3);
A true
X
B
B
false
C 0.3
D ArithmeticException
3/32
![Page 5: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/5.jpg)
Упражнение №1
Задача. Что выведет следующий код?Write(0.1 + 0.2 == 0.3);
A true
X
B
B
false
C 0.3
D ArithmeticException
3/32
![Page 6: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/6.jpg)
Упражнение №1
Задача. Что выведет следующий код?Write(0.1 + 0.2 == 0.3);
A true
X
B
B
false
C 0.3
D ArithmeticException
3/32
![Page 7: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/7.jpg)
Упражнение №1
Задача. Что выведет следующий код?Write(0.1 + 0.2 == 0.3);
A true
X
B
B
false
C 0.3
D ArithmeticException
3/32
![Page 8: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/8.jpg)
Упражнение №1
Задача. Что выведет следующий код?Write(0.1 + 0.2 == 0.3);
A true
X BB false
C 0.3
D ArithmeticException
3/32
![Page 9: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/9.jpg)
[Решение] Упражнение №1
0.1d ≈ 0.100000000000000005551115123125783
+0.2d ≈ 0.2000000000000000111022302462515650.300000000000000044408920985006262
0.3d ≈ 0.299999999999999988897769753748435
Вывод:0.1d + 0.2d 6= 0.3d
4/32
![Page 10: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/10.jpg)
[Решение] Упражнение №1
0.1d ≈ 0.100000000000000005551115123125783+0.2d ≈ 0.200000000000000011102230246251565
0.300000000000000044408920985006262
0.3d ≈ 0.299999999999999988897769753748435
Вывод:0.1d + 0.2d 6= 0.3d
4/32
![Page 11: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/11.jpg)
[Решение] Упражнение №1
0.1d ≈ 0.100000000000000005551115123125783+0.2d ≈ 0.200000000000000011102230246251565
0.300000000000000044408920985006262
0.3d ≈ 0.299999999999999988897769753748435
Вывод:0.1d + 0.2d 6= 0.3d
4/32
![Page 12: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/12.jpg)
[Решение] Упражнение №1
0.1d ≈ 0.100000000000000005551115123125783+0.2d ≈ 0.200000000000000011102230246251565
0.300000000000000044408920985006262
0.3d ≈ 0.299999999999999988897769753748435
Вывод:0.1d + 0.2d 6= 0.3d
4/32
![Page 13: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/13.jpg)
[Решение] Упражнение №1
0.1d ≈ 0.100000000000000005551115123125783+0.2d ≈ 0.200000000000000011102230246251565
0.300000000000000044408920985006262
0.3d ≈ 0.299999999999999988897769753748435
Вывод:0.1d + 0.2d 6= 0.3d
4/32
![Page 14: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/14.jpg)
Упражнение №2
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);GC.KeepAlive(y);
}
X
A
A
true
B false
C ArithmeticException
D Зависит
5/32
![Page 15: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/15.jpg)
Упражнение №2
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);GC.KeepAlive(y);
}
X
A
A
true
B false
C ArithmeticException
D Зависит
5/32
![Page 16: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/16.jpg)
Упражнение №2
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);GC.KeepAlive(y);
}
X
A
A
true
B false
C ArithmeticException
D Зависит
5/32
![Page 17: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/17.jpg)
Упражнение №2
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);GC.KeepAlive(y);
}
X
A
A
true
B false
C ArithmeticException
D Зависит
5/32
![Page 18: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/18.jpg)
Упражнение №2
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);GC.KeepAlive(y);
}
X
A
A
true
B false
C ArithmeticException
D Зависит5/32
![Page 19: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/19.jpg)
Упражнение №2
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);GC.KeepAlive(y);
}
X AA true
B false
C ArithmeticException
D Зависит5/32
![Page 20: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/20.jpg)
Упражнение №3
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);// GC.KeepAlive(y);
}
A true
B false
C ArithmeticException
X
D
D
Зависит
6/32
![Page 21: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/21.jpg)
Упражнение №3
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);// GC.KeepAlive(y);
}
A true
B false
C ArithmeticException
X
D
D
Зависит
6/32
![Page 22: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/22.jpg)
Упражнение №3
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);// GC.KeepAlive(y);
}
A true
B false
C ArithmeticException
X
D
D
Зависит
6/32
![Page 23: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/23.jpg)
Упражнение №3
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);// GC.KeepAlive(y);
}
A true
B false
C ArithmeticException
X
D
D
Зависит
6/32
![Page 24: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/24.jpg)
Упражнение №3
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);// GC.KeepAlive(y);
}
A true
B false
C ArithmeticException
X
D
D
Зависит6/32
![Page 25: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/25.jpg)
Упражнение №3
Задача. Что выведет следующий код?float Sum(float a, float b) => a + b;float x;void Main(){
x = Sum(0.1f, 0.2f);float y = Sum(0.1f, 0.2f);Write(x == y);// GC.KeepAlive(y);
}
A true
B false
C ArithmeticException
X DD Зависит6/32
![Page 26: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/26.jpg)
[Решение] Упражнение №3Ответ.
Debug ReleaseMS.NET true falseMono true true
Объяснение.
ECMA-335, I.12.1.3 “Handling of floating-point data types”
“The nominal type of the variable or expression is eitherfloat32 or float64, but its value can be representedinternally with additional range and/or precision.”
7/32
![Page 27: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/27.jpg)
[Решение] Упражнение №3Ответ.
Debug ReleaseMS.NET true falseMono true true
Объяснение.
ECMA-335, I.12.1.3 “Handling of floating-point data types”
“The nominal type of the variable or expression is eitherfloat32 or float64, but its value can be representedinternally with additional range and/or precision.”
7/32
![Page 28: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/28.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X
B
B
float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 29: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/29.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X
B
B
float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 30: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/30.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X
B
B
float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 31: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/31.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X
B
B
float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 32: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/32.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X
B
B
float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 33: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/33.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X BB float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 34: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/34.jpg)
Упражнение №4
Задача. Умножить 6.2f на 10, результатвернуть в виде int. Получить 62.
A int value1 =(int)(6.2f * 10);
X BB float mul = 6.2f * 10;int value2 = (int)mul;
C A и B правильные
D A и B неправильные
Проверка решения.mcs 4.2.3MSBuild/12.0/Bin/csc.exeRoslyn 1.0.0–1.1.1 Roslyn 1.2.0+
A value1 61 62B value2 62 62
8/32
![Page 35: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/35.jpg)
[Решение] Упражнение №4double d = 6.2f * 10d;// d = 61.9999980926513671875float f = RoundToFloat(d); // f = 62int i1 = TruncToInt(d); // i = 61int i2 = TruncToInt(f); // i = 62
int value1 = (int)(6.2f * 10);// IL_0000: ldc.i4.s 61 or 62 ; int// IL_0002: stloc.0float mul = 6.2f * 10;int value2 = (int)mul;// IL_0003: ldc.r4 62 ; float// IL_0008: conv.i4// IL_0009: ldloc.0
9/32
![Page 36: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/36.jpg)
[Решение] Упражнение №4double d = 6.2f * 10d;// d = 61.9999980926513671875float f = RoundToFloat(d); // f = 62int i1 = TruncToInt(d); // i = 61int i2 = TruncToInt(f); // i = 62int value1 = (int)(6.2f * 10);// IL_0000: ldc.i4.s 61 or 62 ; int// IL_0002: stloc.0
float mul = 6.2f * 10;int value2 = (int)mul;// IL_0003: ldc.r4 62 ; float// IL_0008: conv.i4// IL_0009: ldloc.0
9/32
![Page 37: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/37.jpg)
[Решение] Упражнение №4double d = 6.2f * 10d;// d = 61.9999980926513671875float f = RoundToFloat(d); // f = 62int i1 = TruncToInt(d); // i = 61int i2 = TruncToInt(f); // i = 62int value1 = (int)(6.2f * 10);// IL_0000: ldc.i4.s 61 or 62 ; int// IL_0002: stloc.0float mul = 6.2f * 10;int value2 = (int)mul;// IL_0003: ldc.r4 62 ; float// IL_0008: conv.i4// IL_0009: ldloc.0
9/32
![Page 38: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/38.jpg)
Упражнение №5
Задача. Вычислите следующие величины:Math.Round(-0.5), Math.Round(-1.5)
A Round(-0.5) = 0Round(-1.5) = -1
B Round(-0.5) = -1Round(-1.5) = -2
X
C
C
Round(-0.5) = 0Round(-1.5) = -2
D Round(-0.5) = -1Round(-1.5) = -1
10/32
![Page 39: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/39.jpg)
Упражнение №5
Задача. Вычислите следующие величины:Math.Round(-0.5), Math.Round(-1.5)
A Round(-0.5) = 0Round(-1.5) = -1
B Round(-0.5) = -1Round(-1.5) = -2
X
C
C
Round(-0.5) = 0Round(-1.5) = -2
D Round(-0.5) = -1Round(-1.5) = -1
10/32
![Page 40: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/40.jpg)
Упражнение №5
Задача. Вычислите следующие величины:Math.Round(-0.5), Math.Round(-1.5)
A Round(-0.5) = 0Round(-1.5) = -1
B Round(-0.5) = -1Round(-1.5) = -2
X
C
C
Round(-0.5) = 0Round(-1.5) = -2
D Round(-0.5) = -1Round(-1.5) = -1
10/32
![Page 41: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/41.jpg)
Упражнение №5
Задача. Вычислите следующие величины:Math.Round(-0.5), Math.Round(-1.5)
A Round(-0.5) = 0Round(-1.5) = -1
B Round(-0.5) = -1Round(-1.5) = -2
X
C
C
Round(-0.5) = 0Round(-1.5) = -2
D Round(-0.5) = -1Round(-1.5) = -1
10/32
![Page 42: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/42.jpg)
Упражнение №5
Задача. Вычислите следующие величины:Math.Round(-0.5), Math.Round(-1.5)
A Round(-0.5) = 0Round(-1.5) = -1
B Round(-0.5) = -1Round(-1.5) = -2
X
C
C
Round(-0.5) = 0Round(-1.5) = -2
D Round(-0.5) = -1Round(-1.5) = -1
10/32
![Page 43: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/43.jpg)
Упражнение №5
Задача. Вычислите следующие величины:Math.Round(-0.5), Math.Round(-1.5)
A Round(-0.5) = 0Round(-1.5) = -1
B Round(-0.5) = -1Round(-1.5) = -2
X CC Round(-0.5) = 0Round(-1.5) = -2
D Round(-0.5) = -1Round(-1.5) = -1
10/32
![Page 44: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/44.jpg)
[Решение] Упражнение №5enum MidpointRounding {
AwayFromZero, // Прочь от нуляToEven // К ближайшему чётному
}
static double Round(double value,MidpointRounding mode
)static double Round(
double value) // mode = ToEvenRound(-0.5) = 0Round(-1.5) = -2
11/32
![Page 45: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/45.jpg)
[Решение] Упражнение №5enum MidpointRounding {
AwayFromZero, // Прочь от нуляToEven // К ближайшему чётному
}static double Round(
double value,MidpointRounding mode
)static double Round(
double value) // mode = ToEven
Round(-0.5) = 0Round(-1.5) = -2
11/32
![Page 46: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/46.jpg)
[Решение] Упражнение №5enum MidpointRounding {
AwayFromZero, // Прочь от нуляToEven // К ближайшему чётному
}static double Round(
double value,MidpointRounding mode
)static double Round(
double value) // mode = ToEvenRound(-0.5) = 0Round(-1.5) = -2
11/32
![Page 47: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/47.jpg)
Упражнение №6
Задача. Что выведет следующий код?int x = 2147483584;Write((int)(float)x);
A 2147483584
B 2147483647 (int.MaxValue)
X
C
C
-2147483648 (int.MinValue)
X
D
D
OverflowException
12/32
![Page 48: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/48.jpg)
Упражнение №6
Задача. Что выведет следующий код?int x = 2147483584;Write((int)(float)x);
A 2147483584
B 2147483647 (int.MaxValue)
X
C
C
-2147483648 (int.MinValue)
X
D
D
OverflowException
12/32
![Page 49: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/49.jpg)
Упражнение №6
Задача. Что выведет следующий код?int x = 2147483584;Write((int)(float)x);
A 2147483584
B 2147483647 (int.MaxValue)
X
C
C
-2147483648 (int.MinValue)
X
D
D
OverflowException
12/32
![Page 50: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/50.jpg)
Упражнение №6
Задача. Что выведет следующий код?int x = 2147483584;Write((int)(float)x);
A 2147483584
B 2147483647 (int.MaxValue)
X
C
C
-2147483648 (int.MinValue)
X
D
D
OverflowException
12/32
![Page 51: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/51.jpg)
Упражнение №6
Задача. Что выведет следующий код?int x = 2147483584;Write((int)(float)x);
A 2147483584
B 2147483647 (int.MaxValue)
X
C
C
-2147483648 (int.MinValue)
X
D
D
OverflowException
12/32
![Page 52: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/52.jpg)
Упражнение №6
Задача. Что выведет следующий код?int x = 2147483584;Write((int)(float)x);
A 2147483584
B 2147483647 (int.MaxValue)
X CC -2147483648 (int.MinValue)
X DD OverflowException
12/32
![Page 53: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/53.jpg)
[Решение] Упражнение №6unchecked { Write((int)(float)x); }
⇓x = 2147483584
(float)x = 2147483648 = +231
(int)(float)x = -2147483648 = −231
checked { Write((int)(float)x); }
⇓OverflowException
13/32
![Page 54: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/54.jpg)
[Решение] Упражнение №6unchecked { Write((int)(float)x); }
⇓x = 2147483584
(float)x = 2147483648 = +231
(int)(float)x = -2147483648 = −231
checked { Write((int)(float)x); }
⇓OverflowException
13/32
![Page 55: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/55.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);
A 0
X
B
B
1C -2147483648 (int.MinValue)D OverflowExceptionECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 56: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/56.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);A 0
X
B
B
1C -2147483648 (int.MinValue)D OverflowExceptionECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 57: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/57.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);A 0
X
B
B
1
C -2147483648 (int.MinValue)D OverflowExceptionECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 58: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/58.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);A 0
X
B
B
1C -2147483648 (int.MinValue)
D OverflowExceptionECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 59: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/59.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);A 0
X
B
B
1C -2147483648 (int.MinValue)D OverflowException
ECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 60: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/60.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);A 0
X BB 1C -2147483648 (int.MinValue)D OverflowException
ECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 61: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/61.jpg)
Упражнение №7
Задача. Что выведет следующий код?Write(1 << 32);A 0
X BB 1C -2147483648 (int.MinValue)D OverflowExceptionECMA-334, 14.8 “Shift operators”
“When the type of x is int or uint, the shift count isgiven by the low-order five bits of count.”
int x: (x � 0) = (x � 32) = (x � 64) = . . .long x: (x � 0) = (x � 64) = (x � 128) = . . .
14/32
![Page 62: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/62.jpg)
Упражнение №8
Задача. Выпишите таблицу истинности дляследующих nullable-операций:Write(false | null); Write(true | null);Write(false & null); Write(true & null);Write(false ^ null); Write(true ^ null);
A Код не скомпилируетсяB Все выражения вернут nullC ArithmeticException
X
D
D
Другое
15/32
![Page 63: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/63.jpg)
Упражнение №8
Задача. Выпишите таблицу истинности дляследующих nullable-операций:Write(false | null); Write(true | null);Write(false & null); Write(true & null);Write(false ^ null); Write(true ^ null);
A Код не скомпилируется
B Все выражения вернут nullC ArithmeticException
X
D
D
Другое
15/32
![Page 64: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/64.jpg)
Упражнение №8
Задача. Выпишите таблицу истинности дляследующих nullable-операций:Write(false | null); Write(true | null);Write(false & null); Write(true & null);Write(false ^ null); Write(true ^ null);
A Код не скомпилируетсяB Все выражения вернут null
C ArithmeticException
X
D
D
Другое
15/32
![Page 65: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/65.jpg)
Упражнение №8
Задача. Выпишите таблицу истинности дляследующих nullable-операций:Write(false | null); Write(true | null);Write(false & null); Write(true & null);Write(false ^ null); Write(true ^ null);
A Код не скомпилируетсяB Все выражения вернут nullC ArithmeticException
X
D
D
Другое
15/32
![Page 66: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/66.jpg)
Упражнение №8
Задача. Выпишите таблицу истинности дляследующих nullable-операций:Write(false | null); Write(true | null);Write(false & null); Write(true & null);Write(false ^ null); Write(true ^ null);
A Код не скомпилируетсяB Все выражения вернут nullC ArithmeticException
X
D
D
Другое
15/32
![Page 67: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/67.jpg)
Упражнение №8
Задача. Выпишите таблицу истинности дляследующих nullable-операций:Write(false | null); Write(true | null);Write(false & null); Write(true & null);Write(false ^ null); Write(true ^ null);
A Код не скомпилируетсяB Все выражения вернут nullC ArithmeticException
X DD Другое
15/32
![Page 68: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/68.jpg)
[Решение] Упражнение №8
ECMA-334, 14.10.4 “The bool? logical operators”
В стандарте приводятся таблицы,из которых явно следует:
| null & null ^ nullfalse null false nulltrue true null null
16/32
![Page 69: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/69.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)B x = +∞ (double.PositiveInfinity)C x = −∞ (double.NegativeInfinity)
X
D
D
x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 70: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/70.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)
B x = +∞ (double.PositiveInfinity)C x = −∞ (double.NegativeInfinity)
X
D
D
x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 71: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/71.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)B x = +∞ (double.PositiveInfinity)
C x = −∞ (double.NegativeInfinity)
X
D
D
x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 72: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/72.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)B x = +∞ (double.PositiveInfinity)C x = −∞ (double.NegativeInfinity)
X
D
D
x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 73: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/73.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)B x = +∞ (double.PositiveInfinity)C x = −∞ (double.NegativeInfinity)
X
D
D
x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 74: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/74.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)B x = +∞ (double.PositiveInfinity)C x = −∞ (double.NegativeInfinity)
X DD x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 75: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/75.jpg)
Упражнение №9
Задача. Найдите такое x, для которого функцияCheck вернёт false.bool Check(double x) => x == x;
A @x (Нет такого x)B x = +∞ (double.PositiveInfinity)C x = −∞ (double.NegativeInfinity)
X DD x /∈ R (double.NaN)
ECMA-334, 14.9.2 “Floating-point comparison operators”
If either operand is NaN, the result is false for alloperators except !=, for which the result is true.
17/32
![Page 76: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/76.jpg)
Упражнение №10
Задача. Что выведет следующий код?double x = double.NaN;Write(x == 1.0);
X
A
A
false
B true
C double.NaN
X
D
D
OverflowException
18/32
![Page 77: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/77.jpg)
Упражнение №10
Задача. Что выведет следующий код?double x = double.NaN;Write(x == 1.0);
X
A
A
false
B true
C double.NaN
X
D
D
OverflowException
18/32
![Page 78: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/78.jpg)
Упражнение №10
Задача. Что выведет следующий код?double x = double.NaN;Write(x == 1.0);
X
A
A
false
B true
C double.NaN
X
D
D
OverflowException
18/32
![Page 79: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/79.jpg)
Упражнение №10
Задача. Что выведет следующий код?double x = double.NaN;Write(x == 1.0);
X
A
A
false
B true
C double.NaN
X
D
D
OverflowException
18/32
![Page 80: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/80.jpg)
Упражнение №10
Задача. Что выведет следующий код?double x = double.NaN;Write(x == 1.0);
X
A
A
false
B true
C double.NaN
X
D
D
OverflowException
18/32
![Page 81: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/81.jpg)
Упражнение №10
Задача. Что выведет следующий код?double x = double.NaN;Write(x == 1.0);
X AA false
B true
C double.NaN
X DD OverflowException
18/32
![Page 82: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/82.jpg)
[Решение] Упражнение №10
.NET 027F 0000 0010 0111 1111Delphi 1272 0001 0010 0111 0010
19/32
![Page 83: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/83.jpg)
Упражнение №11
Задача. Найдите такое x для которого функцииNegate1 и Negate2 вернут разные значения.string Binary(double x) => string.Format(
"{0:X16}",BitConverter.DoubleToInt64Bits(x));
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
A @x (Нет такого x)
X
B
B
0 (0)
X
C
C
x /∈ R (double.NaN)D x ≈ 1.79769 · 10308 (double.MaxValue)
20/32
![Page 84: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/84.jpg)
Упражнение №11
Задача. Найдите такое x для которого функцииNegate1 и Negate2 вернут разные значения.string Binary(double x) => string.Format(
"{0:X16}",BitConverter.DoubleToInt64Bits(x));
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
A @x (Нет такого x)
X
B
B
0 (0)
X
C
C
x /∈ R (double.NaN)D x ≈ 1.79769 · 10308 (double.MaxValue)
20/32
![Page 85: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/85.jpg)
Упражнение №11
Задача. Найдите такое x для которого функцииNegate1 и Negate2 вернут разные значения.string Binary(double x) => string.Format(
"{0:X16}",BitConverter.DoubleToInt64Bits(x));
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
A @x (Нет такого x)
X
B
B
0 (0)
X
C
C
x /∈ R (double.NaN)D x ≈ 1.79769 · 10308 (double.MaxValue)
20/32
![Page 86: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/86.jpg)
Упражнение №11
Задача. Найдите такое x для которого функцииNegate1 и Negate2 вернут разные значения.string Binary(double x) => string.Format(
"{0:X16}",BitConverter.DoubleToInt64Bits(x));
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
A @x (Нет такого x)
X
B
B
0 (0)
X
C
C
x /∈ R (double.NaN)
D x ≈ 1.79769 · 10308 (double.MaxValue)
20/32
![Page 87: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/87.jpg)
Упражнение №11
Задача. Найдите такое x для которого функцииNegate1 и Negate2 вернут разные значения.string Binary(double x) => string.Format(
"{0:X16}",BitConverter.DoubleToInt64Bits(x));
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
A @x (Нет такого x)
X
B
B
0 (0)
X
C
C
x /∈ R (double.NaN)D x ≈ 1.79769 · 10308 (double.MaxValue)
20/32
![Page 88: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/88.jpg)
Упражнение №11
Задача. Найдите такое x для которого функцииNegate1 и Negate2 вернут разные значения.string Binary(double x) => string.Format(
"{0:X16}",BitConverter.DoubleToInt64Bits(x));
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
A @x (Нет такого x)X BB 0 (0)X CC x /∈ R (double.NaN)
D x ≈ 1.79769 · 10308 (double.MaxValue)
20/32
![Page 89: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/89.jpg)
[Решение] Упражнение №11
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
Binary(0) == "0000000000000000" // +0.0
Negate1(0) == "8000000000000000" // -0.0Negate2(0) == "0000000000000000" // +0.0
Binary(double.NaN) == "FFF8000000000000"
Negate1(double.NaN) == "7FF8000000000000"Negate2(double.NaN) == "FFF8000000000000"
21/32
![Page 90: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/90.jpg)
[Решение] Упражнение №11
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
Binary(0) == "0000000000000000" // +0.0
Negate1(0) == "8000000000000000" // -0.0Negate2(0) == "0000000000000000" // +0.0
Binary(double.NaN) == "FFF8000000000000"
Negate1(double.NaN) == "7FF8000000000000"Negate2(double.NaN) == "FFF8000000000000"
21/32
![Page 91: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/91.jpg)
[Решение] Упражнение №11
string Negate1(double x) => Binary( -x);string Negate2(double x) => Binary(0-x);
Binary(0) == "0000000000000000" // +0.0
Negate1(0) == "8000000000000000" // -0.0Negate2(0) == "0000000000000000" // +0.0
Binary(double.NaN) == "FFF8000000000000"
Negate1(double.NaN) == "7FF8000000000000"Negate2(double.NaN) == "FFF8000000000000"
21/32
![Page 92: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/92.jpg)
Упражнение №12
Задача. Что выведет следующий код?struct DoubleInt {
public double X;public int Y;
}var a = new DoubleInt { X = +0.0 };var b = new DoubleInt { X = -0.0 };Write(a.Equals(b));
X
A
A
trueB falseC double.NaND Зависит
22/32
![Page 93: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/93.jpg)
Упражнение №12
Задача. Что выведет следующий код?struct DoubleInt {
public double X;public int Y;
}var a = new DoubleInt { X = +0.0 };var b = new DoubleInt { X = -0.0 };Write(a.Equals(b));
X
A
A
true
B falseC double.NaND Зависит
22/32
![Page 94: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/94.jpg)
Упражнение №12
Задача. Что выведет следующий код?struct DoubleInt {
public double X;public int Y;
}var a = new DoubleInt { X = +0.0 };var b = new DoubleInt { X = -0.0 };Write(a.Equals(b));
X
A
A
trueB false
C double.NaND Зависит
22/32
![Page 95: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/95.jpg)
Упражнение №12
Задача. Что выведет следующий код?struct DoubleInt {
public double X;public int Y;
}var a = new DoubleInt { X = +0.0 };var b = new DoubleInt { X = -0.0 };Write(a.Equals(b));
X
A
A
trueB falseC double.NaN
D Зависит
22/32
![Page 96: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/96.jpg)
Упражнение №12
Задача. Что выведет следующий код?struct DoubleInt {
public double X;public int Y;
}var a = new DoubleInt { X = +0.0 };var b = new DoubleInt { X = -0.0 };Write(a.Equals(b));
X
A
A
trueB falseC double.NaND Зависит
22/32
![Page 97: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/97.jpg)
Упражнение №12
Задача. Что выведет следующий код?struct DoubleInt {
public double X;public int Y;
}var a = new DoubleInt { X = +0.0 };var b = new DoubleInt { X = -0.0 };Write(a.Equals(b));
X AA trueB falseC double.NaND Зависит
22/32
![Page 98: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/98.jpg)
Упражнение №13
Задача. Что выведет следующий код?struct DoubleDouble {
public double X;public double Y;
}var a = new DoubleDouble { X = +0.0 };var b = new DoubleDouble { X = -0.0 };Write(a.Equals(b));
A trueB falseC double.NaN
X
D
D
Зависит
23/32
![Page 99: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/99.jpg)
Упражнение №13
Задача. Что выведет следующий код?struct DoubleDouble {
public double X;public double Y;
}var a = new DoubleDouble { X = +0.0 };var b = new DoubleDouble { X = -0.0 };Write(a.Equals(b));
A true
B falseC double.NaN
X
D
D
Зависит
23/32
![Page 100: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/100.jpg)
Упражнение №13
Задача. Что выведет следующий код?struct DoubleDouble {
public double X;public double Y;
}var a = new DoubleDouble { X = +0.0 };var b = new DoubleDouble { X = -0.0 };Write(a.Equals(b));
A trueB false
C double.NaN
X
D
D
Зависит
23/32
![Page 101: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/101.jpg)
Упражнение №13
Задача. Что выведет следующий код?struct DoubleDouble {
public double X;public double Y;
}var a = new DoubleDouble { X = +0.0 };var b = new DoubleDouble { X = -0.0 };Write(a.Equals(b));
A trueB falseC double.NaN
X
D
D
Зависит
23/32
![Page 102: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/102.jpg)
Упражнение №13
Задача. Что выведет следующий код?struct DoubleDouble {
public double X;public double Y;
}var a = new DoubleDouble { X = +0.0 };var b = new DoubleDouble { X = -0.0 };Write(a.Equals(b));
A trueB falseC double.NaN
X
D
D
Зависит23/32
![Page 103: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/103.jpg)
Упражнение №13
Задача. Что выведет следующий код?struct DoubleDouble {
public double X;public double Y;
}var a = new DoubleDouble { X = +0.0 };var b = new DoubleDouble { X = -0.0 };Write(a.Equals(b));
A trueB falseC double.NaN
X DD Зависит23/32
![Page 104: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/104.jpg)
[Решение] Упражнение №13
DoubleInt DoubleDoubleMS.NET true falseMono true true
// MS.NETclass ValueType {
bool Equals (Object obj) {// ...if (CanCompareBits(this))
return FastEqualsCheck(thisObj, obj);// ...
}// Проверяем, что структура "tightly packed"static extern bool CanCompareBits(Object obj);
}
24/32
![Page 105: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/105.jpg)
[Решение] Упражнение №13
DoubleInt DoubleDoubleMS.NET true falseMono true true
// MS.NETclass ValueType {
bool Equals (Object obj) {// ...if (CanCompareBits(this))
return FastEqualsCheck(thisObj, obj);// ...
}// Проверяем, что структура "tightly packed"static extern bool CanCompareBits(Object obj);
}24/32
![Page 106: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/106.jpg)
Упражнение №14
Задача. Найдите три таких числа a, b, c типаdouble (не равных double.NaN), чтобы для нихвыполнилось нижеприведённое неравенство.
(a + b) + c 6= a + (b + c)
A @(a, b, c) (Нет таких чисел)B a = 10100, b = 10100, c = 1
X
C
C
a = 10100, b = −10100, c = 1D a = 10100, b = 10−100, c = 1
25/32
![Page 107: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/107.jpg)
Упражнение №14
Задача. Найдите три таких числа a, b, c типаdouble (не равных double.NaN), чтобы для нихвыполнилось нижеприведённое неравенство.
(a + b) + c 6= a + (b + c)
A @(a, b, c) (Нет таких чисел)
B a = 10100, b = 10100, c = 1
X
C
C
a = 10100, b = −10100, c = 1D a = 10100, b = 10−100, c = 1
25/32
![Page 108: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/108.jpg)
Упражнение №14
Задача. Найдите три таких числа a, b, c типаdouble (не равных double.NaN), чтобы для нихвыполнилось нижеприведённое неравенство.
(a + b) + c 6= a + (b + c)
A @(a, b, c) (Нет таких чисел)B a = 10100, b = 10100, c = 1
X
C
C
a = 10100, b = −10100, c = 1D a = 10100, b = 10−100, c = 1
25/32
![Page 109: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/109.jpg)
Упражнение №14
Задача. Найдите три таких числа a, b, c типаdouble (не равных double.NaN), чтобы для нихвыполнилось нижеприведённое неравенство.
(a + b) + c 6= a + (b + c)
A @(a, b, c) (Нет таких чисел)B a = 10100, b = 10100, c = 1
X
C
C
a = 10100, b = −10100, c = 1
D a = 10100, b = 10−100, c = 1
25/32
![Page 110: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/110.jpg)
Упражнение №14
Задача. Найдите три таких числа a, b, c типаdouble (не равных double.NaN), чтобы для нихвыполнилось нижеприведённое неравенство.
(a + b) + c 6= a + (b + c)
A @(a, b, c) (Нет таких чисел)B a = 10100, b = 10100, c = 1
X
C
C
a = 10100, b = −10100, c = 1D a = 10100, b = 10−100, c = 1
25/32
![Page 111: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/111.jpg)
Упражнение №14
Задача. Найдите три таких числа a, b, c типаdouble (не равных double.NaN), чтобы для нихвыполнилось нижеприведённое неравенство.
(a + b) + c 6= a + (b + c)
A @(a, b, c) (Нет таких чисел)B a = 10100, b = 10100, c = 1
X CC a = 10100, b = −10100, c = 1D a = 10100, b = 10−100, c = 1
25/32
![Page 112: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/112.jpg)
[Решение] Упражнение №14
double a = 1e100, b = -1e100, c = 1;
(a + b) + c = (10100 − 10100) + 1 = 0+ 1 = 1
a+(b+c) = 10100+(−10100+1) = 10100−10100 = 0
26/32
![Page 113: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/113.jpg)
[Решение] Упражнение №14
double a = 1e100, b = -1e100, c = 1;
(a + b) + c = (10100 − 10100) + 1 = 0+ 1 = 1
a+(b+c) = 10100+(−10100+1) = 10100−10100 = 0
26/32
![Page 114: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/114.jpg)
[Решение] Упражнение №14
double a = 1e100, b = -1e100, c = 1;
(a + b) + c = (10100 − 10100) + 1 = 0+ 1 = 1
a+(b+c) = 10100+(−10100+1) = 10100−10100 = 0
26/32
![Page 115: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/115.jpg)
Упражнение №15
Задача. Что выведет следующий код?1
Write("{0:N30}", 24m * 22m / 24m);
X
A
A
22.000000000000000000000000000000B 22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
24 · 2224
=��24 · 22
��24= 22
1Постфикс m означает тип decimal27/32
![Page 116: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/116.jpg)
Упражнение №15
Задача. Что выведет следующий код?1
Write("{0:N30}", 24m * 22m / 24m);
X
A
A
22.000000000000000000000000000000
B 22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
24 · 2224
=��24 · 22
��24= 22
1Постфикс m означает тип decimal27/32
![Page 117: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/117.jpg)
Упражнение №15
Задача. Что выведет следующий код?1
Write("{0:N30}", 24m * 22m / 24m);
X
A
A
22.000000000000000000000000000000B 22.000000000000000000000000001000
C 24.000000000000000000000000000000D OverflowException
24 · 2224
=��24 · 22
��24= 22
1Постфикс m означает тип decimal27/32
![Page 118: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/118.jpg)
Упражнение №15
Задача. Что выведет следующий код?1
Write("{0:N30}", 24m * 22m / 24m);
X
A
A
22.000000000000000000000000000000B 22.000000000000000000000000001000C 24.000000000000000000000000000000
D OverflowException
24 · 2224
=��24 · 22
��24= 22
1Постфикс m означает тип decimal27/32
![Page 119: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/119.jpg)
Упражнение №15
Задача. Что выведет следующий код?1
Write("{0:N30}", 24m * 22m / 24m);
X
A
A
22.000000000000000000000000000000B 22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
24 · 2224
=��24 · 22
��24= 22
1Постфикс m означает тип decimal27/32
![Page 120: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/120.jpg)
Упражнение №15
Задача. Что выведет следующий код?1
Write("{0:N30}", 24m * 22m / 24m);
X AA 22.000000000000000000000000000000B 22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
24 · 2224
=��24 · 22
��24= 22
1Постфикс m означает тип decimal27/32
![Page 121: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/121.jpg)
Упражнение №16
Задача. Что выведет следующий код?Write("{0:N30}", 24m * (22m / 24m));
A 22.000000000000000000000000000000
X
B
B
22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
28/32
![Page 122: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/122.jpg)
Упражнение №16
Задача. Что выведет следующий код?Write("{0:N30}", 24m * (22m / 24m));
A 22.000000000000000000000000000000
X
B
B
22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
28/32
![Page 123: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/123.jpg)
Упражнение №16
Задача. Что выведет следующий код?Write("{0:N30}", 24m * (22m / 24m));
A 22.000000000000000000000000000000
X
B
B
22.000000000000000000000000001000
C 24.000000000000000000000000000000D OverflowException
28/32
![Page 124: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/124.jpg)
Упражнение №16
Задача. Что выведет следующий код?Write("{0:N30}", 24m * (22m / 24m));
A 22.000000000000000000000000000000
X
B
B
22.000000000000000000000000001000C 24.000000000000000000000000000000
D OverflowException
28/32
![Page 125: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/125.jpg)
Упражнение №16
Задача. Что выведет следующий код?Write("{0:N30}", 24m * (22m / 24m));
A 22.000000000000000000000000000000
X
B
B
22.000000000000000000000000001000C 24.000000000000000000000000000000D OverflowException
28/32
![Page 126: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/126.jpg)
Упражнение №16
Задача. Что выведет следующий код?Write("{0:N30}", 24m * (22m / 24m));
A 22.000000000000000000000000000000X BB 22.000000000000000000000000001000
C 24.000000000000000000000000000000D OverflowException
28/32
![Page 127: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/127.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X
C
C
truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 128: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/128.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X
C
C
truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 129: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/129.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X
C
C
truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 130: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/130.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X
C
C
truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 131: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/131.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X
C
C
truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 132: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/132.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X CC truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 133: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/133.jpg)
Упражнение №17
Задача. Что выведет следующий код?var x = 1.0m;var y = 1.00m;Write(x == y);Write(x.ToString() == y.ToString());
A truetrue
B falsefalse
X CC truefalse
D falsetrue
Объяснение.Write(x.ToString()); // "1.0"Write(y.ToString()); // "1.00"
29/32
![Page 134: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/134.jpg)
Упражнение №18*
Задача. Вычислить значение интеграла1:∫ 1
−1
1x
√1+ x
1− xln(2 x2 + 2 x + 12 x2 − 2 x + 1
)dx .
A 2π · arccot√φ
B 4π · arccot√φ
C e iπ − 1D 42
1Cм. http://math.stackexchange.com/q/562694/30/32
![Page 135: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/135.jpg)
Методическая литература
31/32
![Page 136: АндрейАкиньшин,JetBrainspublic.jugru.org/dotnext/2016/spb/day_1/track_1/akinshin.pdf · [Решение] Упражнение №4 doubled =6.2f*10d; // d = 61.9999980926513671875](https://reader034.vdocuments.net/reader034/viewer/2022050105/5f435a23c1f94702c72b7810/html5/thumbnails/136.jpg)
Вопросы?
Андрей Акиньшин, JetBrainshttp://aakinshin.net
https://github.com/AndreyAkinshinhttps://twitter.com/andrey_akinshin
32/32