Code Monkey home page Code Monkey logo

expr's Issues

Missing isnan conditions

Hi,

expr/expr.h

Line 370 in 5e7d72c

case OP_LOGICAL_OR:

If the first expression returns a NAN, then the second element is taken. If the second element is NAN, then a NAN is returned, otherwise 0.

From logical point of view NAN || logic expression returns a logic expression, but logic expression || NAN returns NAN. In general, I'm missing a lot of if isnan() conditions in the code to catch NAN values, for example also for OP_LOGICAL_AND, NAN would also occur here if and only if the second expression is NAN.

Kind regards,

Thaddäus

[FEATURE REQUEST] Error handling

Hi.

Firstly, thanks for this great job!

So, I noticed the library doesn't contains any error handling, and this would be very useful to find errors in complex expressions.

Edit: it was implemented in 2034c85.

cheers

The example in README doesn't compile

The example doesn't compile but a little correction does:

#include "expr.h"

// Custom function that returns the sum of its two arguments
static float add(struct expr_func *f, vec_expr_t args, void *c) {
  float a = expr_eval(&vec_nth(&args, 0));
  float b = expr_eval(&vec_nth(&args, 1));
  return a + b;
}

static struct expr_func user_funcs[] = {
	{"add", add, 0},
	{NULL, NULL, 0},
};

int main() {
	char* a = (char*)malloc(40);
	const char *s = "x = 5, add(2, x)";
  struct expr_var_list vars = {0};
  struct expr *e = expr_create(s, strlen(s), &vars, user_funcs);
  if (e == NULL) {
    printf("Syntax error");
		return 1;
	}

	float result = expr_eval(e);
	printf("result: %f\n", result);

	expr_destroy(e, &vars);
	return 0;
}

However, it doesn't work as expected.

can't compile with strict C99 flags

There seems to be issues with anonymous unions and also with casting function pointers to void*

here are the flags I use

CFLAGS:= -Wfatal-errors -pedantic -Wall -Wextra -Werror -std=c99

While this might seem over fussy, its saved me countless hours of debugging frustration!

Implementation question

This is not an issue, rather a question.

Why is this library implemented as a .h file and not in a .c file? Are there any reason for this excluding performance?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.