Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiqiYu committed Dec 13, 2021
1 parent 895cc2c commit f5dc30d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
Binary file modified week14/Lecture14.pptx
Binary file not shown.
4 changes: 2 additions & 2 deletions week14/examples/error1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

float ratio(float a, float b)
{
if (fabs(a - b) < FLT_EPSILON)
if (fabs(a + b) < FLT_EPSILON)
{
std::cerr << "The two arguments are too close." << std::endl;
std::cerr << "The sum of the two arguments is close to zero." << std::endl;
std::abort();
}
return (a - b) / (a + b);
Expand Down
4 changes: 2 additions & 2 deletions week14/examples/error2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

bool ratio(float a, float b, float & c)
{
if (fabs(a - b) < FLT_EPSILON)
if (fabs(a + b) < FLT_EPSILON)
{
std::cerr << "The two arguments are too close." << std::endl;
std::cerr << "The sum of the two arguments is close to zero." << std::endl;
return false;
}
c = (a - b) / (a + b);
Expand Down
4 changes: 2 additions & 2 deletions week14/examples/error3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

float ratio(float a, float b)
{
if (fabs(a - b) < FLT_EPSILON)
throw "The two arguments are too close.";
if (fabs(a + b) < FLT_EPSILON)
throw "The sum of the two arguments is close to zero.";

return (a - b) / (a + b);
}
Expand Down
4 changes: 2 additions & 2 deletions week14/examples/error4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ float ratio(float a, float b)
throw 1;
if (b < 0)
throw 2;
if (fabs(a - b) < FLT_EPSILON)
throw "The two arguments are too close.";
if (fabs(a + b) < FLT_EPSILON)
throw "The sum of the two arguments is close to zero.";

return (a - b) / (a + b);
}
Expand Down
4 changes: 2 additions & 2 deletions week14/examples/error5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ float ratio(float a, float b)
throw 1;
if (b < 0)
throw 2;
if (fabs(a - b) < FLT_EPSILON)
throw "The two arguments are too close.";
if (fabs(a + b) < FLT_EPSILON)
throw "The sum of the two arguments is close to zero.";

return (a - b) / (a + b);
}
Expand Down
6 changes: 6 additions & 0 deletions week14/examples/nothrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ int main()
else
cout << "So bad, null pointer." << endl;

// for(size_t i = 0; i < length; i++)
// p[i] = i;
// size_t sum;
// for(size_t i = 0; i < length; i++)
// sum += p[i];
// cout << "Sum = " << sum << endl;
if(p)
delete [] p;
return 0;
Expand Down

0 comments on commit f5dc30d

Please sign in to comment.