Skip to content

Instantly share code, notes, and snippets.

@qassa
Created November 14, 2015 18:59
Show Gist options
  • Save qassa/9ac3f6903d9cf985c2e3 to your computer and use it in GitHub Desktop.
Save qassa/9ac3f6903d9cf985c2e3 to your computer and use it in GitHub Desktop.
check if float number is negative?
#include <stdlib.h>
#include <stdio.h>
static int isNegative(float arg){
char *p = (char*) malloc(20);
sprintf(p,"%f",arg);
return p[0] == '-';
}
int main(){
float f = -3;
printf("%d",isNegative(f));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment