# calculated fields

- currently in genappalpha rev 1096 or greater

- calculated fields compute values dynamically during user input
- example
,{ "role" : "input" ,"id" : "m" ,"label" : "mass [kg]" ,"type" : "float" ,"required" : "true" ,"help" : "Enter the mass in kilograms" } ,{ "role" : "input" ,"id" : "c" ,"label" : "Speed of light [m/s]" ,"type" : "float" ,"default" : 299792458 ,"required" : "true" ,"help" : "Enter the speed of light in meters/second" } ,{ "role" : "input" ,"readonly" : "true" ,"id" : "E" ,"label" : "Energy [J]" ,"type" : "text" ,"calc" : "m*c^2" }

- will dynamically update the field "E" when "m" or "c" are changed based upon the calculation E=m*c
^{2 }

- will dynamically update the field "E" when "m" or "c" are changed based upon the calculation E=m*c

## notes

- any id or numeric value should be able to be used
- a calculation can be made on a calculated field
- e.g. we could add to the above example
,{ "role" : "input" ,"readonly" : "true" ,"id" : "logE" ,"label" : "log Energy [J]" ,"type" : "text" ,"calc" : "log(E)" }

- to also get the log of E

- e.g. we could add to the above example
- circular references and syntax errors will generate an error at runtime
- we plan to push this to the generation phase for early checking

## currently supported operations

### binary operators

- + : addition
- - : subtraction
- * : multiplication
- / : division
- ^ : exponentiation

### functions

- abs(x) : absolute value
- acos(x) : arccosine
- asin(x) : arcsine
- atan(x) : arctangent
- atan2(y,x) : tangent of y over x
- ceil(x) : integer round up
- cos(x) : cosine
- exp(x) : e to the power of x
- floor(x) : integer round down
- log(x) : natural log
- max(x,y,...) : maximum
- min(x,y
_{..) : minimum } - pow(x,y) : raise x to the y power
- random() : random # between 0 & 1
- round(x) : round to nearest integer
- sin(x) : sine
- sqrt(x) : square root
- tan(x) : tangent

### repeaters and calc

- calculated fields can be used under repeaters (genappalpha rev >= 1112)
- id's will be taken from the top level (not under a repeater) if they exist
- if the id does not exist at the top level, the one from the same level will be used.
- e.g. this will provide a separate calculation for each repeater count
{ "role" : "input" ,"id" : "ir1" ,"label" : "do calcs" ,"type" : "integer" ,"repeater" : "true" } ,{ "role" : "input" ,"id" : "m" ,"label" : "mass [kg]" ,"type" : "float" ,"required" : "true" ,"help" : "Enter the mass in kilograms" ,"repeat" : "ir1" } ,{ "role" : "input" ,"id" : "c" ,"label" : "Speed of light [m/s]" ,"type" : "float" ,"default" : 299792458 ,"required" : "true" ,"help" : "Enter the speed of light in meters/second" ,"repeat" : "ir1" } ,{ "role" : "input" ,"readonly" : "true" ,"id" : "e" ,"label" : "Energy [J]" ,"type" : "text" ,"calc" : "m*c^2" ,"repeat" : "ir1" }

- and this will also work
{ "role" : "input" ,"id" : "c" ,"label" : "Speed of light [m/s]" ,"type" : "float" ,"default" : 299792458 ,"required" : "true" ,"help" : "Enter the speed of light in meters/second" } ,{ "role" : "input" ,"id" : "ir1" ,"label" : "do calcs" ,"type" : "integer" ,"repeater" : "true" } ,{ "role" : "input" ,"id" : "m" ,"label" : "mass [kg]" ,"type" : "float" ,"required" : "true" ,"help" : "Enter the mass in kilograms" ,"repeat" : "ir1" } ,{ "role" : "input" ,"readonly" : "true" ,"id" : "e" ,"label" : "Energy [J]" ,"type" : "text" ,"calc" : "m*c^2" ,"repeat" : "ir1" }

- e.g. this will provide a separate calculation for each repeater count
- you can not currently mix id's under different repeaters or repeater levels
- if you have a structure that you would like supported, please get in touch

Last modified 9 days ago
Last modified on Feb 17, 2018, 5:19:32 AM