Originally Posted by xpi0t0s
Bit tricky as several variables that have a bearing are not defined (freq, rate, amplitude and probably others); you don't say what output you DO get or what output you get when you miss off the sgn (other than that it is a sine wave).
At a guess you're probably running into C's fondness of converting everything to integers. Try casting maxval to a double and see what happens, i.e.:
int a = sgn(amplitude_scale * sin(phase) * (double)maxval);
Does the sine wave that you get when you miss of sgn() vary from -amplitude_scale*maxval to +amplitude_scale*maxval or from 0 to some maximum? If so then you don't have a sine wave as such, you have sin()+offset, which would not convert to a square with a simple call to sgn(); you would have to subtract the offset, call sgn then add the offset back in.
For more accurate analysis please upload a minimal program that is complete and that shows the output for the two test points pi/2 and 3pi/2 (i.e. the turning points, which will be +1 and -1 whether sgn is called or not).
Of course. How silly of me. Thanks