Skip to content

Commit ed268ea

Browse files
committed
support asin and acos
1 parent d74896e commit ed268ea

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

include/SPTK/math/scalar_operation.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ class ScalarOperation {
245245
*/
246246
bool AddTangentOperation();
247247

248+
/**
249+
* @f$\sin^{-1} x@f$
250+
*
251+
* @return True on success, false on failure.
252+
*/
253+
bool AddArcsineOperation();
254+
255+
/**
256+
* @f$\cos^{-1} x@f$
257+
*
258+
* @return True on success, false on failure.
259+
*/
260+
bool AddArccosineOperation();
261+
248262
/**
249263
* @f$\tan^{-1} x@f$
250264
*

src/main/sopr.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ enum LongOptions {
4848
kSIN,
4949
kCOS,
5050
kTAN,
51+
kASIN,
52+
kACOS,
5153
kATAN,
5254
kTANH,
5355
kATANH,
@@ -94,6 +96,8 @@ void PrintUsage(std::ostream* stream) {
9496
*stream << " -SIN : sine [ sin(x) ]" << std::endl; // NOLINT
9597
*stream << " -COS : cosine [ cos(x) ]" << std::endl; // NOLINT
9698
*stream << " -TAN : tangent [ tan(x) ]" << std::endl; // NOLINT
99+
*stream << " -ASIN : arcsine [ asin(x) ]" << std::endl; // NOLINT
100+
*stream << " -ACOS : arccosine [ acos(x) ]" << std::endl; // NOLINT
97101
*stream << " -ATAN : arctangent [ atan(x) ]" << std::endl; // NOLINT
98102
*stream << " -TANH : hyperbolic tangent [ tanh(x) ]" << std::endl; // NOLINT
99103
*stream << " -ATANH : hyperbolic arctangent [ atanh(x) ]" << std::endl; // NOLINT
@@ -207,6 +211,10 @@ void PrintGeneralErrorMessage(const char* option) {
207211
* - cosine
208212
* - @b -TAN
209213
* - tangent
214+
* - @b -ASIN
215+
* - arcsine
216+
* - @b -ACOS
217+
* - arccosine
210218
* - @b -ATAN
211219
* - arctangent
212220
* - @b -TANH
@@ -259,6 +267,8 @@ int main(int argc, char* argv[]) {
259267
{"SIN", no_argument, NULL, kSIN},
260268
{"COS", no_argument, NULL, kCOS},
261269
{"TAN", no_argument, NULL, kTAN},
270+
{"ASIN", no_argument, NULL, kASIN},
271+
{"ACOS", no_argument, NULL, kACOS},
262272
{"ATAN", no_argument, NULL, kATAN},
263273
{"TANH", no_argument, NULL, kTANH},
264274
{"ATANH", no_argument, NULL, kATANH},
@@ -548,6 +558,20 @@ int main(int argc, char* argv[]) {
548558
}
549559
break;
550560
}
561+
case kASIN: {
562+
if (!scalar_operation.AddArcsineOperation()) {
563+
PrintGeneralErrorMessage("ASIN");
564+
return 1;
565+
}
566+
break;
567+
}
568+
case kACOS: {
569+
if (!scalar_operation.AddArccosineOperation()) {
570+
PrintGeneralErrorMessage("ACOS");
571+
return 1;
572+
}
573+
break;
574+
}
551575
case kATAN: {
552576
if (!scalar_operation.AddArctangentOperation()) {
553577
PrintGeneralErrorMessage("ATAN");

src/math/scalar_operation.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,34 @@ class Tangent : public OperationInterface {
427427
DISALLOW_COPY_AND_ASSIGN(Tangent);
428428
};
429429

430+
class Arcsine : public OperationInterface {
431+
public:
432+
Arcsine() {
433+
}
434+
435+
bool Run(double* number) const override {
436+
*number = std::asin(*number);
437+
return true;
438+
}
439+
440+
private:
441+
DISALLOW_COPY_AND_ASSIGN(Arcsine);
442+
};
443+
444+
class Arccosine : public OperationInterface {
445+
public:
446+
Arccosine() {
447+
}
448+
449+
bool Run(double* number) const override {
450+
*number = std::acos(*number);
451+
return true;
452+
}
453+
454+
private:
455+
DISALLOW_COPY_AND_ASSIGN(Arccosine);
456+
};
457+
430458
class Arctangent : public OperationInterface {
431459
public:
432460
Arctangent() {
@@ -646,6 +674,16 @@ bool ScalarOperation::AddTangentOperation() {
646674
return true;
647675
}
648676

677+
bool ScalarOperation::AddArcsineOperation() {
678+
modules_.push_back(new OperationPerformer(new Arcsine()));
679+
return true;
680+
}
681+
682+
bool ScalarOperation::AddArccosineOperation() {
683+
modules_.push_back(new OperationPerformer(new Arccosine()));
684+
return true;
685+
}
686+
649687
bool ScalarOperation::AddArctangentOperation() {
650688
modules_.push_back(new OperationPerformer(new Arctangent()));
651689
return true;

0 commit comments

Comments
 (0)