question

Jeremy R avatar image
0 Likes"
Jeremy R asked Phil BoBo commented

Infinity as a double

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).

FlexSim 19.2.0
FlexSim 18.2.3
flexsim 18.2.3doubleinfinfinity
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anthony.johnson avatar image
1 Like"
anthony.johnson answered Phil BoBo commented

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.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

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

0 Likes 0 ·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Phil BoBo commented

They are defined as FlexScript macros in the main tree.

MAIN:/project/exec/globals/fsmacros

You write in your code only the name of macro to get the value returned.

· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeremy R avatar image Jeremy R commented ·

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 0 ·
Joerg Vogel avatar image Joerg Vogel Jeremy R commented ·

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 0 ·
Jeremy R avatar image Jeremy R Joerg Vogel commented ·

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 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.