-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.cpp
72 lines (62 loc) · 1.25 KB
/
Utility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//----------------------------------------------
// Implementation of general utility routines
//----------------------------------------------
//
// Programmer: Donald House
// Date: March 8, 1999
//
// Copyright (C) - Donald H. House. 2005
//
using namespace std;
#include "Utility.h"
/*
computes sqrt(a^2 + b^2) without destructive underflow or overflow
*/
double pythag(double a, double b)
{
double absa, absb;
absa = Abs(a);
absb = Abs(b);
if(absa > absb)
return absa * sqrt(1.0 + Sqr(absb / absa));
else if(absb > 0)
return absb * sqrt(1.0 + Sqr(absa / absb));
else
return 0;
}
/*
Utility message routines
*/
void prompt(char *s)
{
cout << s << " ";
}
void message(char *s1, char *s2, char *s3)
{
cout << s1;
if(s2 != NULL && strlen(s2) > 0)
cout << " " << s2;
if(s3 != NULL && strlen(s3) > 0)
cout << " " << s3;
cout << endl;
}
void status(char *s1, char *s2, char *s3)
{
cout << "Status: ";
message(s1, s2, s3);
}
void error(char *s1, char *s2, char *s3)
{
cerr << "Error: ";
cerr << s1;
if(s2 != NULL && strlen(s2) > 0)
cerr << " " << s2;
if(s3 != NULL && strlen(s3) > 0)
cerr << " " << s3;
cerr << endl;
}
void abort(char *s1, char *s2, char *s3)
{
error(s1, s2, s3);
exit(1);
}