Let's say you want mint a token TOK that is pegged to the USD. Then following must hold:
TOKUSD = USDTOK = 1
USDETH = 1/ETHUSD
TOKETH = 1/ETHTOK
The formula of the exchange rate is
TOKETH = TOKUSD * USDETH = USDETH.
If ETH rises against the USD your token price goes down.
if TOKETH = USDETH = 10, 10 TOK * ETHTOK = 10 TOK / TOKETH = 1 ETH = 10 USD
if TOKETH = USDETH = 20, 10 TOK / 20 = 0.5 ETH = 10 USD
if TOKETH = USDETH = 5, 10 TOK / 5 = 2 ETH = 10 USD
Since Solidity has no float point regime, a division will always result in integers. Tracking the price of USDETH correctly seems not feasable.
How can one accurately code the conversion rates, without loss?