Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error expected but not given for str vs num comparison #7961

Closed
p5pRT opened this issue Jun 8, 2005 · 4 comments
Closed

error expected but not given for str vs num comparison #7961

p5pRT opened this issue Jun 8, 2005 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 8, 2005

Migrated from rt.perl.org#36217 (status was 'resolved')

Searchable as RT36217$

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2005

From fdjcomp@yahoo.com

Dear Perl people​:

I got very puzzled with the following situation​:
using '==' for numeric equality on string "23.456 7
/s"
versus the number 23.456, it tests OK/TRUE while I
would
think it should be FALSE.

Please see the attached script for an example.

under perl at least a warning is produced
"Argument "23.456 7 /s" isn't numeric in numeric eq
(==)
at F​:\myperl\pl\tp\tp119.pl line 16"

but in Test​::More​::cmp_ok the test is simply reported
ok, without any warnings!

Can somebody explain? Into what trap did I fall? Or is
this a feature and does it have an explanation?

Long live Perl
thank you for your attention

Frederik

#<-BEGIN
script---------------------------------------------->
#!/usr/bin/perl -w

use strict;
use warnings;

#a string
my $kstr = "23.456 7 /s";

#a number
my $knum = 23.456;

if ($kstr eq $knum) {print "OP eq OK\n"} else {print
"OP eq not OK\n\n"}

if ($kstr == $knum) {print "OP == OK\n"} else {print
"OP == not OK\n\n"}

use Test​::More;
BEGIN { plan tests => 2};

print "\ncmp_ok 'eq' fails as expected \n";

cmp_ok($kstr, 'eq', $knum, "OP eq OK");

print "\ncmp_ok '==' should give not OK IMHO\n\n";

cmp_ok($kstr, '==', $knum, "OP == OK");
print "\nbut cmp_ok '==' gives OK??\n\n\n";

#<-END
script----------------------------------------------------->

#########HERE is the bug info as requested

perl -v and perlbug -d information follows​:

#<------------------------------------------------------------------>

perl -v produced​:

Binary build 811 provided by ActiveState Corp.
http​://www.ActiveState.com
ActiveState is a division of Sophos.
Built Dec 13 2004 09​:52​:01

#<---------------------------------------------------------------------------->

perlbug -d produced​:


Flags​:
  category=
  severity=


Site configuration information for perl v5.8.6​:

Configured by ActiveState at Mon Dec 13 09​:51​:32 2004.

Summary of my perl5 (revision 5 version 8 subversion
6) configuration​:
  Platform​:
  osname=MSWin32, osvers=4.0,
archname=MSWin32-x86-multi-thread
  uname=''
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=define use5005threads=undef
useithreads=define usemultiplicity=d
efine
  useperlio=define d_sfio=undef uselargefiles=define
usesocks=undef
  use64bitint=undef use64bitall=undef
uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi
-DNDEBUG -O1 -DWIN32 -D_CONSOLE
-DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED
-DPERL_IMPLICIT_CONTEXT -DPERL_IM
PLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
  optimize='-MD -Zi -DNDEBUG -O1',
  cppflags='-DWIN32'
  ccversion='', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234
  d_longlong=undef, longlongsize=8,
d_longdbl=define, longdblsize=10
  ivtype='long', ivsize=4, nvtype='double',
nvsize=8, Off_t='__int64', lseeks
ize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -debug
-opt​:ref,icf -libpath​:"F
:\perl586\lib\CORE" -machine​:x86'
  libpth=\lib
  libs= oldnames.lib kernel32.lib user32.lib
gdi32.lib winspool.lib comdlg3
2.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws
2_32.lib mpr.lib winmm.lib version.lib odbc32.lib
odbccp32.lib msvcrt.lib
  perllibs= oldnames.lib kernel32.lib user32.lib
gdi32.lib winspool.lib com
dlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib netapi32.lib uuid.li
b ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib
odbccp32.lib msvcrt.lib
  libc=msvcrt.lib, so=dll, useshrplib=yes,
libperl=perl58.lib
  gnulibc_version='undef'
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef,
ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo
-nodefaultlib -debug -opt​:ref,icf
-libpath​:"F​:\perl586\lib\CORE" -machine​:x86'

Locally applied patches​:
  ACTIVEPERL_LOCAL_PATCHES_ENTRY
  21540 Fix backward-compatibility issues in if.pm
  23565 Wrong MANIFEST.SKIP


@​INC for perl v5.8.6​:
  F​:/perl586/lib
  F​:/perl586/site/lib
  .


Environment for perl v5.8.6​:
  HOME=E​:\TXT_docs_2005\comp\vim_config
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
 
PATH=F​:\perl586\bin\;d​:\xp_bat;C​:\WINDOWS\system32;C​:\WINDOWS;C​:\WINDOWS\Sy
stem32\Wbem;C​:\j2sdk\bin;d​:\Borland\Bcc55\bin;f​:\miktex\miktex\bin;d​:\xp_graphi
cs\imgmagic557q8;
  PERL_BADLANG (unset)
  SHELL (unset)

#<------------------------------------------------------------------->

 
__________________________________
Do you Yahoo!?
Make Yahoo! your home page
http​://www.yahoo.com/r/hs

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2005

From @schwern

On Wed, Jun 08, 2005 at 09​:09​:14AM -0000, fredaa elder wrote​:

I got very puzzled with the following situation​:
using '==' for numeric equality on string "23.456 7
/s"
versus the number 23.456, it tests OK/TRUE while I
would
think it should be FALSE.

Its true because the numification of "23.456 7 /s" is 23.456. Perl tries to
figure out what you meant.

under perl at least a warning is produced
"Argument "23.456 7 /s" isn't numeric in numeric eq
(==)
at F​:\myperl\pl\tp\tp119.pl line 16"

Perl is warning you, "I did the best I can, but its really not a number".

but in Test​::More​::cmp_ok the test is simply reported
ok, without any warnings!

Warnings are turned off inside cmp_ok() for reasons I can't quite remember
at the moment. Turning warnings back on exposes a minor bug in cmp_ok()
where cmp_ok($obj, '==', 42) treats the $obj as a string, incorrect if
$obj is numericly overloaded.

I've taken over these bugs into Test-Simple.
https://rt.cpan.org/NoAuth/Bug.html?id=13155
https://rt.cpan.org/NoAuth/Bug.html?id=13156

--
Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern
You are wicked and wrong to have broken inside and peeked at the
implementation and then relied upon it.
  -- tchrist in <31832.969261130@​chthon>

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 24, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant