Skip to content

Using C++ conditional operators #149

@nixwang

Description

@nixwang

I define a function like this. I have ensured the pos_x is right from 0.0 to 10.0. But the output is always 0.0, seen that the comparison do not work.

AD<double> _threshold = 4.8;
AD<double> _p_set = 0.48;
AD<double> _zero_set = 0.0;
AD<double> get_p(AD<double> pos_x){
  return (pos_x > _threshold) ? _pitch_set : _zero_set;
}

So I tested the output of 'AD pos_x'. test1 can output the right data from 0.0 to 10.0, but test2 output the wrong data with always 0.0.

test1

AD<double> get_p(AD<double> pos_x){
    return pos_x;
  }

test2

AD<double> get_p(AD<double> pos_x){
  double _pos_x = Value( Var2Par(pos_x));
  return _pos_x;
}

So can you provide any suggestion please, thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions