Ticket #1239 (new cage)

Opened 5 years ago

Last modified 5 years ago

configuration: define MIN/MAX macros for all integral typedefs

Reported by: kjs Owned by:
Priority: normal Milestone:
Component: none Version: 1.7.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description (last modified by kjs) (diff)

It's great to have INTVAL and UINTVAL, but without MAX_INTVAL it's kind of hard to work with them in some respects. All integral typedefs should have min/max macros. Syntax not a big deal, it can be fixed later, just don't break anything when introducing them. -- Chip Salzenberg <chip@…>

PREVIOUSLY tracked in RT#39855

Change History

Changed 5 years ago by kjs

Nothing has happened on this ticket since it was introduced in 2006. Do we need MIN/MAX macros? If so, why, or where do we expect them to be used?

Pm

Changed 5 years ago by kjs

Defining them on a 2's complement machine would be easy as pie:

#define MAX_UINTVAL (UINTVAL)((INTVAL)-1)
#define MIN_UINTVAL (UINTVAL)0
#define MAX_INTVAL (((INTVAL)-1) / 2)
#define MIN_INTVAL ((~MAX_INTVAL) + 1)

...and repeat for any other integral typedefs we have.

I do we even support any architecture that isn't 2's complement-based?

--Andrew Whitworth

Changed 5 years ago by kjs

+1 to apply and resolve.

cotto

Changed 5 years ago by kjs

I think that that would be better defined in terms of ~0

#define MIN_UINTVAL (UINTVAL)0

This one, I think is correct.

#define MAX_INTVAL (((INTVAL)-1) / 2)

Eh? -1/2 is 0 for signed integer arithmetic.

#define MIN_INTVAL ((~MAX_INTVAL) + 1)

Even with the correct definition of MAX_INTVAL, that's going to be out by 1. For a two's complement system, it doesn't need the + 1.

The logic that Perl 5 uses to do this is described here:

http://perl5.git.perl.org/perl.git/blob/HEAD:/perl.h#l2178

I suspect it's portable.

Nicholas Clark

Changed 5 years ago by kjs

The current intended names for that macros are PARROT_INTVAL_MAX, PARROT_INTVAL_MIN, and so on.

The last work in this matter is: include/parrot/platform_limits.h

-- Salu2

Changed 5 years ago by kjs

It looks like those comments in platform_limits.h are out-of-place. PARROT_INTVAL_MIN and PARROT_INTVAL_MAX are defined in include/parrot/config.h, although the definition may not be as flexible as the macros in perl.h that Nicholas mentioned. It might be beneficial to incorporate them into what we're currently using, but I'm not a good judge of that.

The definitions in parrot's config.h come, as one would expect, from config/auto/format.pm. (TT #530 addresses this.) It should be pretty simple to add the code needed to figure out which macros to use for the missing min/max values. The min/max are currently defined for INTVAL and FLOATVAL, so definitions are needed for UINTVAL, HUGEINTVAL, UHUGEINTVAL and HUGEFLOATVAL. Once those are in place, this ticket can go away.

cotto

Changed 5 years ago by kjs

platform_limits.h is intended for platforms where there is no limits.h and the macros must be taken from another include file, or explicitly defined. Also, when someone wants to build with different integer types and the detection of appropriate limit values for that types fails.

config.h conditionally does his own definitions after including platform_limits. If that definitions do the right thing platform_limits does not need to do nothing. Consequently, the generic version does nothing.

-- Salu2

Changed 5 years ago by kjs

  • description modified (diff)
Note: See TracTickets for help on using tickets.