last day (15 days later) » 

3:09 AM
43
Q: Can mathematical operators *, /, +, -, ^ be used to convert a non-zero number to 1?

daveI am working with software (Oracle Siebel) that only supports JavaScript expressions with operators multiply, divide, subtract, add, and XOR (*, /, -, +, ^). I don't have other operators such as ! or ?: available. Using the above operators, is it possible to convert a number to 1 if it is non-ze...

 
so, only setting values and comparing, not even if statement?
 
Is c,by any chance, always integer?
 
Do you have a limit of the precision of the number? Or is it always an integer?
 
By default javascript have set of conversions inside for comparing, for example: 0 is false and non-zero values are converted astrue
 
is it possible to convert a number to 1 if it is non-zero? contradicts with I tried c / c , but it evaluates to NaN when c is 0.
 
3:09 AM
@JaredGoguen it can have at most 2 trailing digits, it is a currency value. The maximum leading digits is 12.
 
@dave storing money in floating point numbers, uh-oh
 
@jrook i see your point, but i added that an additional requirement is if c is 0 then d must be 0.
 
user3277192
floating point and XOR ... not sure how javascript stores floating points (nor if it's standardised between browsers), but it can be tricky to use bitwise operators on floating point data.
 
There must be a mistake. Siebel does support javasript in its entirety. Siebel's eScript is ECMA compliant. It supports 'if' statements and ternary operators. That is a simple '!=0' is all it takes. Have been doing it for years now.
2
 
So you don't have ==?
 
3:09 AM
If you have logical operators, then c && c / c
 
1 - 0 ** c, if exponentiation is allowed?
 
Do you confirm that ^ is bitwise XOR and not exponentiation, as it would seem from here, for instance?
 
I am pretty sure that you have a CASE statement available to you. (And really you should just ask a question with your real problem... en.wikipedia.org/wiki/XY_problem )
2
 
This doesn't answer the question, but to expand on something mentioned in another comment: you should really never use floating point to represent currency values. Also, I agree that the question itself sounds like an XY problem.
 
Are you talking about mathematics or JavaScript? What's that ^ doing there?
 

last day (15 days later) »