Infinity as a double

Infinity as a double

jeremy_r
Not applicable
256 Views
8 Replies
Message 1 of 9

Infinity as a double

jeremy_r
Not applicable

[ FlexSim 18.2.3 ]

Is there an intended way to assign the value of infinity to a double?

I can produce the value from the expression 1/0, but I was wondering if there is some intended way to specifically return that value so that I can assign a double to that value. Something like "double.inf" or some kind of Global Macro (like INT_MAX).

0 Likes
Accepted solutions (1)
257 Views
8 Replies
Replies (8)
Message 2 of 9

joerg_vogel_HsH
Mentor
Mentor

They are defined as FlexScript macros in the main tree.

MAIN:/project/exec/globals/fsmacros

27373-global-macros-max-limits.png

You write in your code only the name of macro to get the value returned.
0 Likes
Message 3 of 9

jeremy_r
Not applicable

Neither of those macros seems to actually return infinity though.

double test = 1/0;
return test;

The above code returns a value that the console displays as "inf".

But if I use GLOBAL_DELAYINDEFINITE or GLOBAL_UNREACHABLE, I get the value that appears as the macro definition.

0 Likes
Message 4 of 9

joerg_vogel_HsH
Mentor
Mentor

Maybe I made a mistake and took a picture of wrong macros. Perhaps you look by yourself in node fsmacros of main tree. Or the values are large enough to be seen as infinite to limit needed space in system memory. And perhaps you describe where and why you need such a large value.

0 Likes
Message 5 of 9

jeremy_r
Not applicable

I had taken a look at those macros before asking the question, but wasn't able to find anything, which is why I asked on the forums, in case I had missed it.

I probably could just use a very large value rather than floating-point infinity. However, since FlexSim clearly already supports floating-point infinity (as demonstrated when you try to divide by zero), I was hoping to use that value instead of a really large value for semantic reasons (and clarity of code).

I had hoped there might be some built-in way in FlexScript to assign infinity to a double (since calculating 1/0 to access it concerns me, given that in a purely mathematical sense that's not correct). But perhaps the answer is simply that there is no such method.

0 Likes
Message 6 of 9

Ben_WilsonADSK
Community Manager
Community Manager

@Jordan Johnson, @phil.bobo, does FlexSim have any way to represent infinity?

0 Likes
Message 7 of 9

philboboADSK
Autodesk
Autodesk


Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 8 of 9

anthony_johnsonT83CM
Autodesk
Autodesk
Accepted solution

There is no macro that returns infinity in FlexScript. You can try 1 / 0, but I'm not sure that is the same as C++'s std::numeric_limits<double>::infinity, and I don't know why just using one of the existing macros (or defining your own) would not suffice.

Message 9 of 9

philboboADSK
Autodesk
Autodesk

What existing macro returns the max value of a double? Should a user be using GLOBAL_UNREACHABLE for that?



Phil BoBo
Sr. Manager, Software Development
0 Likes