| 343 | } |
| 344 | |
| 345 | func signedDiv(numerator, denominator, out *int256, gas *uint64) *int256 { |
| 346 | sn := Sign(numerator, gas) |
| 347 | sd := Sign(denominator, gas) |
| 348 | if sn == 0 && sd == 0 { // TODO correct? xor just sd == 0 ? |
| 349 | out = nil |
| 350 | return nil |
| 351 | } |
| 352 | if sn == 0 { |
| 353 | out = New(0, gas) |
| 354 | return out |
| 355 | } |
| 356 | |
| 357 | n := *numerator |
| 358 | if sn == -1 { |
| 359 | Neg(numerator, &n, gas) |
| 360 | } |
| 361 | |
| 362 | d := *denominator |
| 363 | if sd == -1 { |
| 364 | Neg(denominator, &d, gas) |
| 365 | } |
| 366 | |
| 367 | Div(&n, &d, out, gas) |
| 368 | |
| 369 | if (sn == -1) != (sd == -1) { |
| 370 | Neg(out, out, gas) |
| 371 | } |
| 372 | |
| 373 | return out |
| 374 | } |
| 375 | |
| 376 | // out = {c: d1.c, q: 10^max(d1.q - d2.q, 0)} |
| 377 | func add_helper(d1, d2 *Decimal, gas *uint64) (out int256) { |