GithubHelp home page GithubHelp logo

chocolateboy / scalar-util-numeric Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 114 KB

Numeric tests for perl scalars

Home Page: http://search.cpan.org/dist/Scalar-Util-Numeric/

License: Artistic License 2.0

Perl 68.71% XS 31.29%
perl-module cpan cpan-module xs type

scalar-util-numeric's Introduction

Scalar::Util::Numeric

Build Status CPAN Version

NAME

Scalar::Util::Numeric - numeric tests for perl scalars

SYNOPSIS

use Scalar::Util::Numeric qw(isnum isint isfloat);

foo($bar / 2) if (isnum $bar);

if (isint $baz) {
    # ...
} elsif (isfloat $baz) {
    # ...
}

DESCRIPTION

This module exports a number of wrappers around perl's builtin grok_number function, which returns the numeric type of its argument, or 0 if it isn't numeric.

TAGS

All of the functions exported by Scalar::Util::Numeric can be imported by using the :all tag:

use Scalar::Util::Numeric qw(:all);

EXPORTS

isnum

isnum ($val)

Returns a nonzero value (indicating the numeric type) if $val is a number.

The numeric type is a conjunction of the following flags:

0x01  IS_NUMBER_IN_UV               (number within UV range - not necessarily an integer)
0x02  IS_NUMBER_GREATER_THAN_UV_MAX (number is greater than UV_MAX)
0x04  IS_NUMBER_NOT_INT             (saw . or E notation)
0x08  IS_NUMBER_NEG                 (leading minus sign)
0x10  IS_NUMBER_INFINITY            (Infinity)
0x20  IS_NUMBER_NAN                 (NaN - not a number)

isint

isuv

isbig

isfloat

isneg

isinf

isnan

The following flavours of isnum (corresponding to the flags above) are also available:

isint
isuv
isbig
isfloat
isneg
isinf
isnan

isint returns -1 if its operand is a negative integer, 1 if it's 0 or a positive integer, and 0 otherwise.

The others always return 1 or 0.

uvmax

Returns UV_MAX, the largest UV (unsigned integer value).

VERSION

0.40

SEE ALSO

AUTHORS

COPYRIGHT AND LICENSE

Copyright © 2003-2020 by chocolateboy.

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

scalar-util-numeric's People

Contributors

arc avatar chocolateboy avatar schwern avatar

Watchers

 avatar  avatar  avatar

scalar-util-numeric's Issues

Scalar::Util::Numeric results do not agree with Scalar::Util::looks_like_number

It appears that the Scalar::Util::Numeric set of functions reports true for words that Scalar::Util::looks_like_number reports as non-numbers.

$ perl -MScalar::Util=looks_like_number -MScalar::Util::Numeric=isnum,isinf,isnan -E 'for my $n (qw( infinity infinite nan nano )) { say join("\t", sprintf("%8s", $n), map { 0+$_ } looks_like_number($n), isnum($n), isinf($n), isnan($n) ) }'
infinity	1	20	1	0
infinite	0	84	1	0
     nan	1	36	0	1
    nano	0	100	0	1

I would expect that infinite and nano to not be treated as numbers, and therefor isnum, isinf, and isnan would return 0.

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.