math problems
Posted: Fri May 19, 2017 10:42 am
Is there a good solution in pb for avoiding conversion errors from string to double ???
Code: Select all
;testprogram snippet
;purpose milling a circle with depth increment
T_total$="2.00" ;result inputgadget T_total depth
T_increment$="0.20" ;result inputgadget increment depth/pass
increment.d=ValD(T_increment$) ;convert to double
total.d=ValD(T_total$)
new_total.d=0
;Debug increment ;Small conversion error,I suppose this is normal
;Debug total
Repeat
new_total=new_total+increment
Debug new_total
Until new_total>= total
;problem :The loop is run ONCE too much
;So you have To take this into account !!!
;I try the same in BASCOM (basic for microcontroller) and this works well ,I don't know in other programming languages?
;I can work around this problem
;total=Int(total*1000)
;increment=Int(increment*1000) ;this works,is there a better solution in purebasic ??
;Debug total