---------------------------------------------------------------------------
| 509 | |
| 510 | //--------------------------------------------------------------------------- |
| 511 | void EbuCore_WithFactor(Node* Parent, const string& Name, const Ztring& Rational, const Ztring& Num, const Ztring& Den) |
| 512 | { |
| 513 | Ztring nominal, factorNumerator, factorDenominator; |
| 514 | int64u num=0, den=0; |
| 515 | if (!Num.empty() && !Den.empty()) |
| 516 | { |
| 517 | size_t Dot=Num.rfind(__T('.')); //Num can be a float (e.g. in DisplayAspectRatio) |
| 518 | if (Dot==string::npos) |
| 519 | { |
| 520 | num=Num.To_int64u(); |
| 521 | den=Den.To_int64u(); |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | den=(int64u)float64_int64s(pow((float64)10, (int)(Num.size()-(Dot+1)))); |
| 526 | num=(int64u)float64_int64s(Num.To_float64()*den*Den.To_int64u()); |
| 527 | } |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | size_t Dot=Rational.rfind(__T('.')); |
| 532 | if (Dot==string::npos) |
| 533 | { |
| 534 | //This is already an integer |
| 535 | if (Name.empty()) |
| 536 | nominal=Rational; |
| 537 | else |
| 538 | { |
| 539 | factorNumerator=Rational; |
| 540 | factorDenominator.From_Number(1); |
| 541 | } |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | //this is a float, converting it to num/den |
| 546 | den=(int64u)float64_int64s(pow((float64)10, (int)(Rational.size()-(Dot+1)))); |
| 547 | num=(int64u)float64_int64s(Rational.To_float64()*den); |
| 548 | } |
| 549 | } |
| 550 | if (num && den) |
| 551 | { |
| 552 | //We need to find the nearest integer and adapt factors |
| 553 | float64 nom=((float64)num)/den; |
| 554 | int64u nom_rounded=(int64u)float64_int64s(nom); |
| 555 | int64u num2=float64_int64s(((float64)num)/(nom_rounded)); |
| 556 | int64u den2=float64_int64s(num/nom); |
| 557 | if (!Name.empty() && num2==den2) |
| 558 | { |
| 559 | //This is an integer, no need of factor numbers |
| 560 | nominal.From_Number(nom_rounded); |
| 561 | } |
| 562 | else if (!Name.empty() && ((float64)num2)/den2*nom_rounded==nom) //If we find an exact match |
| 563 | { |
| 564 | //We found it, we can have good integer and factor numbers |
| 565 | factorNumerator.From_Number(num2); |
| 566 | factorDenominator.From_Number(den2); |
| 567 | nominal.From_Number(nom_rounded); |
| 568 | } |
no test coverage detected