mmorise / World

A high-quality speech analysis, manipulation and synthesis system
http://www.kisc.meiji.ac.jp/~mmorise/world/english
Other
1.17k stars 251 forks source link

add include cstdlib #16

Closed yamachu closed 7 years ago

yamachu commented 7 years ago

Error occurred when compiling src/harvest.cpp

g++ -O1 -Wall -fPIC  -Isrc -o "build/objs/world/harvest.o" -c "src/harvest.cpp"
src/harvest.cpp: In function ‘int {anonymous}::ExtendF0(const double*, int, int, int, int, double**, int, double, double*)’:
src/harvest.cpp:826:41: error: ‘abs’ was not declared in this scope
   int distance = abs(last_point - origin);
                                         ^
make: *** [build/objs/world/harvest.o] エラー 1

build environment

gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
Ubuntu 14.04.5 LTS"

same error occurred on macOS

mkdir -p ./build/objs/world
g++ -O1 -Wall -fPIC  -Isrc -o "build/objs/world/harvest.o" -c "src/harvest.cpp"
src/harvest.cpp:826:18: error: use of undeclared identifier 'abs'; did you mean 'fabs'?
  int distance = abs(last_point - origin);
                 ^~~
                 fabs
/usr/include/math.h:431:15: note: 'fabs' declared here
extern double fabs(double);
              ^
src/harvest.cpp:826:18: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
  int distance = abs(last_point - origin);
                 ^
src/harvest.cpp:826:18: note: use function 'std::abs' instead
  int distance = abs(last_point - origin);
                 ^~~
                 std::abs
src/harvest.cpp:826:18: note: include the header <cstdlib> or explicitly provide a declaration for 'std::abs'
1 warning and 1 error generated.
make: *** [build/objs/world/harvest.o] Error 1

not checked on Windows...

and I tried use commit https://github.com/mmorise/World/commit/d6f8c56a7e2c3701b5ac468dc9fcd3d3928d1ce1 , it works.

mmorise commented 7 years ago

Thank you for your request. Since the function abs() often causes bugs, I would like to propose the use of an original function MyAbsInt().

static inline int MyAbsInt(int x) { return x > 0 ? x : -x; }

Is this idea ok?

yamachu commented 7 years ago

looks good to me :+1:

mmorise commented 7 years ago

Thank you very much. I updated harvest.cpp.