equal
deleted
inserted
replaced
1 "{ Encoding: utf8 }" |
|
2 |
|
3 " |
1 " |
4 COPYRIGHT (c) 2001 by eXept Software AG |
2 COPYRIGHT (c) 2001 by eXept Software AG |
5 All Rights Reserved |
3 All Rights Reserved |
6 |
4 |
7 This software is furnished under a license and may be used |
5 This software is furnished under a license and may be used |
39 ! |
37 ! |
40 |
38 |
41 documentation |
39 documentation |
42 " |
40 " |
43 Raised when a division by zero is attempted. |
41 Raised when a division by zero is attempted. |
|
42 |
|
43 To get the (in our oppinion: invalid) behavior of some programming languages such as JavaSript, |
|
44 which do not report division by zero exceptions, |
|
45 use the following code: |
|
46 |
|
47 ZeroDivide ignoreIn:[ x / 0.0 ] |
|
48 |
|
49 i.e. |
|
50 ZeroDivide ignoreIn:[ 1.0 / 0.0 ] |
|
51 returns +Inf, |
|
52 and |
|
53 ZeroDivide ignoreIn:[ -1.0 / 0.0 ] |
|
54 returns -Inf instead. |
44 " |
55 " |
45 ! |
56 ! |
46 |
57 |
47 examples |
58 examples |
48 " |
59 " |
76 ! ! |
87 ! ! |
77 |
88 |
78 !ZeroDivide methodsFor:'accessing'! |
89 !ZeroDivide methodsFor:'accessing'! |
79 |
90 |
80 defaultResumeValue |
91 defaultResumeValue |
81 "return infinity here, if ever proceeded" |
92 "return +/- infinity here, if ever proceeded" |
82 |
93 |
83 ^ parameter receiver class infinity |
94 |poorReceiver| |
|
95 |
|
96 (poorReceiver := self dividend) negative ifTrue:[ |
|
97 ^ poorReceiver class negativeInfinity |
|
98 ]. |
|
99 ^ poorReceiver class infinity |
84 |
100 |
85 " |
101 " |
86 |a b| |
102 |a b| |
87 |
103 |
88 a := 5. |
104 a := 5. |
96 " |
112 " |
97 |
113 |
98 " |
114 " |
99 |a b| |
115 |a b| |
100 |
116 |
101 a := 5.0. |
117 a := -5.0. |
102 b := 0.0. |
118 b := 0.0. |
103 ZeroDivide handle:[:ex | |
119 ZeroDivide handle:[:ex | |
104 Transcript showCR:('division by zero - dividend was: ' , ex dividend printString). |
120 Transcript showCR:('division by zero - dividend was: ' , ex dividend printString). |
105 ex proceed |
121 ex proceed |
106 ] do:[ |
122 ] do:[ |
107 a / b |
123 a / b |
108 ] |
124 ] |
109 " |
125 " |
|
126 |
|
127 "Modified: / 20-06-2017 / 15:37:59 / cg" |
110 ! |
128 ! |
111 |
129 |
112 dividend |
130 dividend |
113 "Return the number that was being divided by zero." |
131 "Return the number that was being divided by zero." |
114 |
132 |