in reply to Re^2: Largest integer in 64-bit perl
in thread Largest integer in 64-bit perl

”…weird lesson to take. You'll have "problems near 2**53" in those languages too!”

I'm not so sure about that. Or at least I don't see the problems:

use anyhow::{Context, Result}; use num::BigUint; fn frob(n: u64) -> Result<BigUint> { Ok((1..=n) .into_iter() .map(|i| BigUint::from(i)) .reduce(|a, b| a * b) .context("fuba")?) } fn main() -> Result<()> { println!("i8 {}", i8::MAX); println!("i16 {}", i16::MAX); println!("i32 {}", i32::MAX); println!("i64 {}", i64::MAX); println!("i128 {}", i128::MAX); println!("u8 {}", u8::MAX); println!("u16 {}", u16::MAX); println!("u32 {}", u32::MAX); println!("u64 {}", u64::MAX); println!("u128 {}", u128::MAX); println!("f32 {}", f32::MAX); println!("f64 {}", f64::MAX); println!("{}", frob(1000)?); Ok(()) }
i8 127 i16 32767 i32 2147483647 i64 9223372036854775807 i128 170141183460469231731687303715884105727 u8 255 u16 65535 u32 4294967295 u64 18446744073709551615 u128 340282366920938463463374607431768211455 f32 340282350000000000000000000000000000000 f64 179769313486231570000000000000000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000 4023872600770937735437024339230039857193748642107146325437999104299385 +123986290205920442084869694048004799886101971960586316668729948085589 +013238296699445909974245040870737599188236277271887325197795059509952 +76120874975462497043601418278094646496291056393887437886487337119181\ 0458257836478499770124766328898359557354325131853239584630755574091142 +624174743493475534286465766116677973966688202912073791438537195882498 +081268678383745597317461360853795345242215865932019280908782973084313 +92844403281231558611036976801357304216168747609675871348312025478589\ 3207671691324484262361314125087802080002616831510273418279777047846358 +681701643650241536913982812648102130927612448963599287051149649754199 +093422215668325720808213331861168115536158365469840467089756029009505 +37616475847728421889679646244945160765353408198901385442487984959953\ 3191017233555566021394503997362807501378376153071277619268490343526252 +000158885351473316117021039681759215109077880193931781141945452572238 +655414610628921879602238389714760885062768629671466746975629112340824 +39208160153780889893964518263243671616762179168909779911903754031274\ 6222899880051954444142820121873617459926429565817466283029555702990243 +241531816172104658320367869061172601587835207515162842255402651704833 +042261439742869330616908979684825901254583271682264580665267699586526 +82272807075781391858178889652208164348344825993266043367660176999612\ 8318607883861502794659551311565520360939881806121385586003014356945272 +242063446317974605946825731037900840244324384656572450144028218852524 +709351906209290231364932734975655139587205596542287497740114133469627 +15422845862377387538230483865688976461927383814900140767310446640259\ 8994902222217659043399018860185665264850617997023561938970178600408118 +897299183110211712298459016419210688843871218556461249607987229085192 +968193723886426148396573822911231250241866493531439701374285319266498 +75337218940694281434118520158014123344828015051399694290153483077644\ 5690990731524332782882698646027898643211390835062170950025973898635542 +771967428222487575867657523442202075736305694988250879689281627538488 +633969099598262809561214509948717012445164612603790293091208890869420 +28510640182154399457156805941872748998094254742173582401063677404595\ 7417851608292301353580818400969963725242305608559037006242712434169090 +041536901059339838357779394109700277534720000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000

In any case, this seems to be a clearly defined matter in this case.

Replies are listed 'Best First'.
Re^4: Largest integer in 64-bit perl
by LanX (Saint) on May 29, 2025 at 21:12 UTC
    The discussion in this thread is about the side effects of implicit typecasting/conversions of whole numbers to augment precision when operations may cause an overflow.

    Perl does this by switching to double floats with E0 were the mantissa has 53 bits (opposed to integers with 32 or 64 bits, depending on the built).

    Now from what I read on Wikipedia is Rust strictly typed.

    Hence I really don't understand what your code is supposed to show.

    Is there any implicit typecasting in your code?°

    update

    According to this tutorial: https://oylenshpeegul.gitlab.io/from-perl-to-rust/numbers.html this can't be, because coercion has to be made explicitly.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Perl does this by switching to double floats ...

      Rather, perl switches to "NV" floats.
      Of course, I'm nitpicking, but it's a nitpick that does have some significance.
      On a perl whose ivsize=8, && whose nvtype is either 'long double' or '__float 128', I get:
      D:\>perl -e "print 'wtf' unless ~0 < (~0) + 1;" D:\>
      But on a perl where ivsize=8 and nvtype is 'double' and you get:
      D:\>perl -e "print 'wtf' unless ~0 < (~0) + 1;" wtf D:\>
      Now that particular configuration (ivsize==8 and nvtype is 'double') is the only perl configuration that produces that nonsense - and yet it's the most commonly used configuration !!
      If you use either an ivsize of 4, or an nvtype that is not double, then you can ignore that particular weirdness because it's not going to happen.

      Note: That "nonsense" doesn't just happen with (~0) + 1. It happens for (~0) + $x for all $x in the range 1..2048.
      That's mainly why I think of it as an insane configuration. (It's still a configuration that I regularly use ;-)

      Cheers,
      Rob
        So what do you expect to happen if you construct the max unsigned integer via bitwise inverting zero ~0 and adding 1 ?

        You are talking about "weirdness", so what would be "normal" in your opinion.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

Re^4: Largest integer in 64-bit perl
by LanX (Saint) on May 29, 2025 at 13:22 UTC
    That's Raku/Perl6?

    (at least I'm not aware of any other language applying use to import a module)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      ”…any other language applying use…”

      There are some more:

      with Alien; with Utils; use Utils; package Superiour is type Acme is new Alien.Object with null record; function Shred (Self : Object) return String; end Superiour;
Re^4: Largest integer in 64-bit perl
by ikegami (Patriarch) on May 29, 2025 at 16:50 UTC

    I don't see any incrementing beyond 2**53 (or any incrementing at all) in there. I don't know what you're trying to prove, but it doesn't relate to the passage you quoted.