| Author |
Message |
snovotill
Joined: Feb 8, 2013 Posts: 80
|
Posted: Jan 18, 2014 11:27 AM Post subject: Type Casting in Expression Evaluator |
|
Hi Jarek, I've had another run-in with Floats vs Double in ExressionEvaluator. Is there an easy fix for this one?
Out9=1/(In3+1); //Calculate duty cycle from inhale to exhale ratio. Out1=In1<In2*(1-Out9)? In1/In2/(1-Out9): (In2-In1)/In2/Out9; //Ramp. Out2=In1<In2*(1-Out9)? 1: 0; //Inhale outputs 1 and Exhale outputs 0. Out3=In1<In2*(1-Out9)? Math.sqrt((1-In1/In2/(1-Out9))*In1/In2/(1-Out9)): 0;
If I simply remove \"Math.sqrt\" from the fourth line it starts working fine. I've tried to put an \"f\" in various places but no go. The error I get is:
Reinit problem in element Inhale/Exhale Generator(1297): n: Expression compilation failed. For more details see messages on console C:Program Files (x86)BioEraPro mpExprEval_2_Inhale.java:11: error: possible loss of precision Out3=In1<In2*(1-Out9)? Math.sqrt((1-In1/In2/(1-Out9))*In1/In2/(1-Out9)): 0; //Reversed; ^ required: float found: double 1 error
Thanks for looking. Stepan |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1073
|
Posted: Jan 18, 2014 7:21 PM Post subject: |
|
Yes, add \"(float)\" like that:
(float) Math.sqrt(...)
|
|
 |
snovotill
Joined: Feb 8, 2013 Posts: 80
|
Posted: Jan 18, 2014 8:42 PM Post subject: |
|
Thanks Jarek =) For the benefit of others I'd like to post your other hint here too: To typecast constants, just end the number with 'f' like this: 0.128f |
|
 |
jarek
Joined: Oct 22, 2007 Posts: 1073
|
Posted: Jan 18, 2014 9:05 PM Post subject: |
|
Yes, those rules are for the advanced form of the expression though.
The default and most often used form doesn't require anything like that. |
|