Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29283 Discussions

Setting upper and lower limits to integer variable values

warwickb1
Beginner
821 Views

Hi,

I would like to create a Percentage Type variable that can only have integer values between 0 and 100.  I can't see a way of specifying such a type.  The only limits that I can see are those that can be applied is to dimensions, not values.  Am I missing something, please?

0 Kudos
1 Solution
andrew_4619
Honored Contributor III
821 Views

You could make your percentage variables/types within a module and make use of public an private attributes. You could make some functions such that the percentage types are set / modified/ accessed via module functions that enforce some rules perhaps. Not knowing axactly what you are trying to do it is hard to be more specific.

View solution in original post

0 Kudos
2 Replies
DavidWhite
Valued Contributor II
821 Views

This doesn't answer your question about creating a type that can only have the values 0 to 100, but you can force values between 0 and 100 by using

Value = Min(Max(Value,0),100)

Regards,

David

0 Kudos
andrew_4619
Honored Contributor III
822 Views

You could make your percentage variables/types within a module and make use of public an private attributes. You could make some functions such that the percentage types are set / modified/ accessed via module functions that enforce some rules perhaps. Not knowing axactly what you are trying to do it is hard to be more specific.

0 Kudos
Reply