A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/jb55/is_number.c below:

jb55/is_number.c: Test a string to see if it's a number. Very fast!

Very fast number testing

Install with clib

$ clib install jb55/is_number.c
#include "is_number/is_number.h"
#include <assert.h>

int main() {
  const char *str = "1.0";
  int is_num;

  is_num = is_number("1.0", 3);
  assert(is_num);

  is_num = is_number_with("1.", 2, ALLOW_EMPTY_POST_DOT);
  assert(is_num);

  is_num = is_number("1.", 2);
  assert(!is_num);
}
enum is_num_options {
  ALLOW_EMPTY_PRE_DOT  = 1 << 1,  // allow empty digits before the decimal point
  ALLOW_EMPTY_POST_DOT = 1 << 2,  // allow empty digits past the decimal point
  STRICT_WHITESPACE    = 1 << 3,  // don't allow space padding
  ONLY_TEST_INT        = 1 << 4   // don't allow decimals/floats
};

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4