Skip to content

Test a string to see if it's a number. Very fast!

Notifications You must be signed in to change notification settings

jb55/is_number.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is_number.c

Build Status

Very fast number testing

Installation

Install with clib

$ clib install jb55/is_number.c

Example

#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);
}

Options

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
};

About

Test a string to see if it's a number. Very fast!

Resources

Stars

Watchers

Forks

Packages

No packages published