[r2038] Weird randart thing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miyazaki
    Adept
    • Jan 2009
    • 227

    [r2038] Weird randart thing

    Found this randart in the spoilers:

    Code:
    The Spear 'Rhorlata' (3d6) (-11,-7)
    -----------------------------------
    Heavily cursed.
    Slays giants.
    Cannot be harmed by acid, electricity, fire, cold.
    Aggravates creatures nearby.  Drains experience.  Induces random
    teleportation.  
    
    
    Min Level 1, Max Level 0, Generation chance 40, Power 4294967291, 5.0 lbs
  • juggle5
    Scout
    • Feb 2009
    • 30

    #2
    Looks like a signed/unsigned int bug. If the power was set to -5 (is a negative power allowed?), but printed as an unsigned integer, then the output would be 4294967291.

    Comment

    • emulord
      Adept
      • Oct 2009
      • 207

      #3
      Looks like the Power calculation overflowed to negative. Thats near MaxUnsignedLong. It wont ever generate, but if it could it would be worth a lot according to power based pricing (??)

      Comment

      • Pete Mack
        Prophet
        • Apr 2007
        • 6883

        #4
        No overflow, just a formating problem in the log file.
        There are a handful of negative power artifacts. (Nobody sane would use Mormegil or Beruthiel, unless it's some kind of crazy challenge.)

        Comment

        • miyazaki
          Adept
          • Jan 2009
          • 227

          #5
          I wondered more about the max depth.

          Comment

          • Magnate
            Angband Devteam member
            • May 2007
            • 5110

            #6
            Originally posted by miyazaki
            I wondered more about the max depth.
            Max depth is also based on power, so anything with negative power will have max depth 0. I will fix this soon, so max depth is never below 100.

            @Pete: what's the right %foo formatting to print a signed int instead of unsigned?
            "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

            Comment

            • Pete Mack
              Prophet
              • Apr 2007
              • 6883

              #7
              @magnate:
              In the unlikely event that you haven't figured this out already:
              Code:
              printf("%u", i);

              Comment

              • Magnate
                Angband Devteam member
                • May 2007
                • 5110

                #8
                Originally posted by Pete Mack
                @magnate:
                In the unlikely event that you haven't figured this out already:
                Code:
                printf("%u", i);
                Thanks Pete - how fabulously counter-intuitive is that! %d for UNsigned, %u for signed!
                "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

                Comment

                • PowerDiver
                  Prophet
                  • Mar 2008
                  • 2820

                  #9
                  Originally posted by Magnate
                  Thanks Pete - how fabulously counter-intuitive is that! %d for UNsigned, %u for signed!
                  Why would you ever want to do that? The only time I care how I print unsigned stuff is bit flags or pointers or the like, and those I want in hex. The standard %d works fine unless the high order bit is 1. If you have real unsigned stuff with high bit of 1, you are playing with fire because you'll have overflow errors sooner or really sooner.

                  If you have an unsigned char packed into a normal char, %d combined with a cast of the argument works fine.

                  Comment

                  • d_m
                    Angband Devteam member
                    • Aug 2008
                    • 1517

                    #10
                    Originally posted by Magnate
                    Thanks Pete - how fabulously counter-intuitive is that! %d for UNsigned, %u for signed!
                    I think you have this backwards:

                    Code:
                    #import <stdio.h>
                    int main(void) {
                        unsigned int i = -1;
                        printf("%d %u\n", i, i);
                        return 0;
                    }
                    Produces:

                    Code:
                    -1 4294967295
                    linux->xterm->screen->pmacs

                    Comment

                    • Pete Mack
                      Prophet
                      • Apr 2007
                      • 6883

                      #11
                      Sorry Magnate, I misread. %u is Unsigned decimal, %d is signed Decimal.

                      Comment

                      • Magnate
                        Angband Devteam member
                        • May 2007
                        • 5110

                        #12
                        Originally posted by Pete Mack
                        Sorry Magnate, I misread. %u is Unsigned decimal, %d is signed Decimal.
                        Then something odd is going on. This all started because negative power ratings get printed out unsigned in the artifact spoiler ... but I didn't know about %u, so I'm certain I'm using %d ...
                        "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

                        Comment

                        • Pete Mack
                          Prophet
                          • Apr 2007
                          • 6883

                          #13
                          Did you verify that you are printing a signed number in the first place?

                          If you are casting--say--(byte) to (int), you will always get an unsigned integer.
                          You may need to cast to (char) first: (int)((char)x)

                          Edit:
                          Fixed, per Zaimoni's comment.
                          Last edited by Pete Mack; September 7, 2010, 21:37.

                          Comment

                          • zaimoni
                            Knight
                            • Apr 2007
                            • 590

                            #14
                            Originally posted by Pete Mack
                            Did you verify that you are printing a signed number in the first place?

                            If you are casting--say--(byte) to (int), you will always get a signed integer.
                            You may need to cast to (char) first: (int)((char)x)
                            Actually, on normal platforms casting byte/unsigned char to int will be a strictly positive number after the cast.

                            Casting signed char to int works as expected. Of course, since it is target-dependent whether char acts like signed char or unsigned char things can go weird.
                            Zaiband: end the "I shouldn't have survived that" experience. V3.0.6 fork on Hg.
                            Zaiband 3.0.10 ETA Mar. 7 2011 (Yes, schedule slipped. Latest testing indicates not enough assert() calls to allow release.)
                            Z.C++: pre-alpha C/C++ compiler system (usable preprocessor). Also on Hg. Z.C++ 0.0.10 ETA December 31 2011

                            Comment

                            • Pete Mack
                              Prophet
                              • Apr 2007
                              • 6883

                              #15
                              @Zaimoni--
                              My bad: I meant to say: you will always get the signedness of the original value.
                              Fixed in original.

                              Comment

                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎