List of usage examples for org.apache.commons.lang.math Fraction getFraction
public static Fraction getFraction(int numerator, int denominator)
Creates a Fraction instance with the 2 parts of a fraction Y/Z.
Any negative signs are resolved to be on the numerator.
From source file:MainClass.java
public static void main(String[] args) { Fraction numer1 = Fraction.getFraction(3, 4); Fraction numer2 = Fraction.getFraction(51, 3509); Fraction numerator = numer1.multiplyBy(numer2); Fraction denominator = Fraction.getFraction(41, 59); Fraction result = numerator.divideBy(denominator); System.out.println("Expression as Fraction: " + result.reduce().toString()); System.out.println("Expression as double: " + result.doubleValue()); Fraction test1 = Fraction.getFraction(1, 2); Fraction test2 = Fraction.getFraction(2, 4); System.out.println("1/2 equals 2/4: " + test1.equals(test2)); double value = Fraction.getFraction(10000, 100000).pow(6).doubleValue(); double reduced = Fraction.getFraction(10000, 100000).reduce().pow(6).doubleValue(); System.out.println("Fraction to pow 6 without reduction: " + value); System.out.println("Fraction to pow 6 with reduction: " + reduced); }
From source file:com.castlabs.dash.helpers.ManifestHelper.java
public static String convertFramerate(double vrate) { Fraction f1 = Fraction.getFraction((int) (vrate * 1001), 1001); Fraction f2 = Fraction.getFraction((int) (vrate * 1000), 1000); double d1 = Math.abs(f1.doubleValue() - vrate); double d2 = Math.abs(f2.doubleValue() - vrate); if (d1 < d2) { return f1.getNumerator() + "/" + f1.getDenominator(); } else {// w w w . j a v a 2s. com return f2.getNumerator() + "/" + f2.getDenominator(); } }
From source file:com.castlabs.dash.helpers.ManifestHelper.java
/** * Creates a representation and AudioChannelConfiguration if appropriate. *///from ww w .ja v a2 s. c om public static RepresentationType createRepresentation(AdaptationSetType adaptationSet, Track track) { RepresentationType representation = adaptationSet.addNewRepresentation(); if (track.getHandler().equals("vide")) { long videoHeight = (long) track.getTrackMetaData().getHeight(); long videoWidth = (long) track.getTrackMetaData().getWidth(); double framesPerSecond = (double) (track.getSamples().size() * track.getTrackMetaData().getTimescale()) / track.getDuration(); Fraction fraction = Fraction.getFraction((int) videoWidth, (int) videoHeight).reduce(); adaptationSet.setPar("" + fraction.getNumerator() + ":" + fraction.getDenominator()); //representation.setMimeType("video/mp4"); representation.setCodecs(DashHelper.getRfc6381Codec(track.getSampleDescriptionBox().getSampleEntry())); representation.setWidth(videoWidth); representation.setHeight(videoHeight); representation.setFrameRate(convertFramerate(framesPerSecond)); representation.setSar("1:1"); // too hard to find it out. Ignoring even though it should be set according to DASH-AVC-264-v2.00-hd-mca.pdf } if (track.getHandler().equals("soun")) { AudioSampleEntry ase = (AudioSampleEntry) track.getSampleDescriptionBox().getSampleEntry(); //representation.setMimeType("audio/mp4"); representation.setCodecs(DashHelper.getRfc6381Codec(ase)); representation.setAudioSamplingRate("" + DashHelper.getAudioSamplingRate(ase)); DescriptorType audio_channel_conf = representation.addNewAudioChannelConfiguration(); DashHelper.ChannelConfiguration cc = DashHelper.getChannelConfiguration(ase); audio_channel_conf.setSchemeIdUri(cc.schemeIdUri); audio_channel_conf.setValue(cc.value); } return representation; }
From source file:org.oscarehr.common.model.ReportStatistic.java
public ReportStatistic(int count, int size) { fraction = Fraction.getFraction(count, size); }
From source file:org.oscarehr.common.model.ReportStatistic.java
public void setSize(int size) { fraction = Fraction.getFraction(getCount(), size); }
From source file:org.richfaces.tests.metamer.ftest.extension.attributes.coverage.result.SimpleCoverageResult.java
private Fraction getFractionFromEnumSets(EnumSet numerator, EnumSet denominator) { return Fraction.getFraction(numerator.size(), denominator.size()); }