Skip to content

Instantly share code, notes, and snippets.

@hughrawlinson
Last active November 11, 2021 10:21
Show Gist options
  • Save hughrawlinson/d78f8faf459fab0341f7 to your computer and use it in GitHub Desktop.
Save hughrawlinson/d78f8faf459fab0341f7 to your computer and use it in GitHub Desktop.
A small operation of basic fuzzy logic functions in C++
/**
@file fuzzylogic.c
@ingroup mc2liveAlg
hugh rawlinson - mu202hr@gold.ac.uk
**/
#include <stdio.h>
double fuzzyOR(double a, double b){
if(a>b){
return a;
} else{
return b;
}
}
double fuzzyAND(double a, double b){
if(a<b){
return a;
} else{
return b;
}
}
double fuzzyNOT(double a){
return 1.0 - a;
}
double fuzzyNOR(double a, double b){
return fuzzyNOT(fuzzyOR(a,b));
}
double fuzzyNAND(double a, double b){
return fuzzyNOT(fuzzyAND(a,b));
}
double fuzzyIMPLY(double a, double b){
return fuzzyOR(fuzzyNOT(a),b);
}
double fuzzyXOR(double a, double b){
double or = fuzzyOR(a,b);
return fuzzyAND(or,fuzzyNOT(or));
}
double fuzzyEQUIV(double a, double b){
return fuzzyNOT(fuzzyXOR(a,b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment