Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.89k stars 538 forks source link

[doc] Perlnumber vs. -12.34e$x #18735

Open jidanni opened 3 years ago

jidanni commented 3 years ago

perlnumber says

SYNOPSIS
           $n = 1234;              # decimal integer
           $n = 0b1110011;         # binary integer
           $n = 01234;             # octal integer
           $n = 0x1234;            # hexadecimal integer
           $n = 12.34e-56;         # exponential notation
           $n = "-12.34e56";       # number specified as a string
           $n = "1234";            # number specified as a string

OK, but do mention somewhere on the page how to get that 56 in dynamically. E.g.,

$ perl -lwe '$x= 56; $n = "-12.34e$x"; print for $n, $n+0;'
-12.34e56
-1.234e+57
karenetheridge commented 3 years ago

Which dynamic method were you thinking of?

I would just do 12.34 * 10**-56.

jidanni commented 3 years ago

I would just do 12.34 * 10**-56.

That's cheating. Your job is to show the user how to get that number in before the "e" the best way!

It's just like if one could write -5, but not -$x.

jidanni commented 3 years ago

Also + seems much less computationally expensive than **.