Skip to content

Instantly share code, notes, and snippets.

@tsutsui
Created January 15, 2023 07:52
Show Gist options
  • Select an option

  • Save tsutsui/2d52ddc65e22711332fb89d1d2c8de42 to your computer and use it in GitHub Desktop.

Select an option

Save tsutsui/2d52ddc65e22711332fb89d1d2c8de42 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int cmp(double d1, double d2)
{
if (d1 == d2) return 0;
else if (d1 - d2 < 0) return -1;
else return 1;
}
int main()
{
int ret, exp;
double d1, d2;
d1 = 3.0; d2 = 3.0; exp = 0; ret = cmp(d1, d2);
if (exp != ret)
printf(" wrong result d1: %f d2: %f exp: %d ret: %d\n", d1, d2, exp, ret);
d1 = 0.0; d2 = 3.0; exp = -1; ret = cmp(d1, d2);
if (exp != ret)
printf(" wrong result d1: %f d2: %f exp: %d ret: %d\n", d1, d2, exp, ret);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment