1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.UnitInterface;
5 import org.djunits.unit.Unitless;
6
7 /**
8 * Dimensionless quantity.
9 * <p>
10 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
11 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
12 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
13 * @author Alexander Verbraeck
14 */
15 public class Dimensionless extends Quantity<Dimensionless>
16 {
17 /** Constant with value zero. */
18 public static final Dimensionless ZERO = ofSi(0.0);
19
20 /** Constant with value one. */
21 public static final Dimensionless ONE = ofSi(1.0);
22
23 /** Constant with value NaN. */
24 @SuppressWarnings("checkstyle:constantname")
25 public static final Dimensionless NaN = ofSi(Double.NaN);
26
27 /** Constant with value POSITIVE_INFINITY. */
28 public static final Dimensionless POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
29
30 /** Constant with value NEGATIVE_INFINITY. */
31 public static final Dimensionless NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
32
33 /** Constant with value MAX_VALUE. */
34 public static final Dimensionless POS_MAXVALUE = ofSi(Double.MAX_VALUE);
35
36 /** Constant with value -MAX_VALUE. */
37 public static final Dimensionless NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
38
39 /** */
40 private static final long serialVersionUID = 600L;
41
42 /**
43 * Instantiate a Dimensionless quantity with an SI or base value and a display unit.
44 * @param value the quantity value expressed in the SI or base unit
45 * @param displayUnit the display unit to use
46 * @param useSi use SI value when true, use value in unit when false
47 */
48 public Dimensionless(final double value, final Unitless displayUnit, final boolean useSi)
49 {
50 super(value, displayUnit, useSi);
51 }
52
53 /**
54 * Instantiate a Dimensionless quantity expressed in the given unit.
55 * @param valueInUnit the quantity value expressed in the given unit
56 * @param unit the unit of the value, also acts as the display unit
57 */
58 public Dimensionless(final double valueInUnit, final Unitless unit)
59 {
60 this(valueInUnit, unit, false);
61 }
62
63 /**
64 * Return a Dimensionless instance based on an SI value.
65 * @param si the si value
66 * @return the Dimensionless instance based on an SI value
67 */
68 public static Dimensionless ofSi(final double si)
69 {
70 return new Dimensionless(si, Unitless.BASE, true);
71 }
72
73 /**
74 * Instantiate a Dimensionless quantity with an SI or base value and a display unit.
75 * @param siValue the quantity value expressed in the SI or base unit
76 * @param displayUnit the display unit to use
77 * @return the Dimensionless instance based on an SI value with the given display unit
78 */
79 public static Dimensionless ofSi(final double siValue, final Unitless displayUnit)
80 {
81 return new Dimensionless(siValue, displayUnit, true);
82 }
83
84 @Override
85 public Dimensionless instantiateSi(final double siValue, final UnitInterface<Dimensionless> displayUnit)
86 {
87 return new Dimensionless(siValue, (Unitless) displayUnit, true);
88 }
89
90 /**
91 * Returns a Dimensionless representation of a textual representation of a value with a unit. The String representation that
92 * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
93 * allowed, but not required, between the value and the unit.
94 * @param text the textual representation to parse into a Dimensionless
95 * @return the Scalar representation of the value in its unit
96 * @throws IllegalArgumentException when the text cannot be parsed
97 * @throws NullPointerException when the text argument is null
98 */
99 public static Dimensionless valueOf(final String text)
100 {
101 return Quantity.valueOf(text, ZERO);
102 }
103
104 /**
105 * Returns a Dimensionless based on a value expressed in the unit.
106 * @param valueInUnit the value, expressed in the given unit
107 * @param unit the unit of the value, also acts as the display unit
108 * @return ab Dimensionless representation of the value in its unit
109 */
110 public static Dimensionless of(final double valueInUnit, final Unitless unit)
111 {
112 return new Dimensionless(valueInUnit, unit);
113 }
114
115 /**
116 * Returns a Dimensionless based on a value and the textual representation of the unit, which can be localized.
117 * @param valueInUnit the value, expressed in the unit as given by unitString
118 * @param unitString the textual representation of the unit
119 * @return the Scalar representation of the value in its unit
120 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
121 * @throws NullPointerException when the unitString argument is null
122 */
123 public static Dimensionless of(final double valueInUnit, final String unitString)
124 {
125 return Quantity.of(valueInUnit, unitString, ZERO);
126 }
127
128 @Override
129 public Unitless getDisplayUnit()
130 {
131 return (Unitless) super.getDisplayUnit();
132 }
133
134 /**
135 * Calculate the division of Dimensionless and Dimensionless, which results in a Dimensionless quantity.
136 * @param v quantity
137 * @return quantity as a division of Dimensionless and Dimensionless
138 */
139 public Dimensionless divide(final Dimensionless v)
140 {
141 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
142 }
143
144 /**
145 * Calculate the division of Dimensionless and Length, which results in a LinearObjectDensity scalar.
146 * @param v scalar
147 * @return scalar as a division of Dimensionless and Length
148 */
149 public LinearObjectDensity divide(final Length v)
150 {
151 return new LinearObjectDensity(this.si() / v.si(), LinearObjectDensity.Unit.SI);
152 }
153
154 /**
155 * Calculate the division of Dimensionless and LinearObjectDensity, which results in a Length scalar.
156 * @param v scalar
157 * @return scalar as a division of Dimensionless and LinearObjectDensity
158 */
159 public Length divide(final LinearObjectDensity v)
160 {
161 return new Length(this.si() / v.si(), Length.Unit.SI);
162 }
163
164 /**
165 * Calculate the division of Dimensionless and Duration, which results in a Frequency scalar.
166 * @param v scalar
167 * @return scalar as a division of Dimensionless and Duration
168 */
169 public Frequency divide(final Duration v)
170 {
171 return new Frequency(this.si() / v.si(), Frequency.Unit.SI);
172 }
173
174 /**
175 * Calculate the division of Dimensionless and Frequency, which results in a Duration scalar.
176 * @param v scalar
177 * @return scalar as a division of Dimensionless and Frequency
178 */
179 public Duration divide(final Frequency v)
180 {
181 return new Duration(this.si() / v.si(), Duration.Unit.SI);
182 }
183
184 /**
185 * Calculate the division of Dimensionless and ElectricalConductance, which results in a ElectricalResistance scalar.
186 * @param v scalar
187 * @return scalar as a division of Dimensionless and ElectricalConductance
188 */
189 public ElectricalResistance divide(final ElectricalConductance v)
190 {
191 return new ElectricalResistance(this.si() / v.si(), ElectricalResistance.Unit.SI);
192 }
193
194 /**
195 * Calculate the division of Dimensionless and ElectricalResistance, which results in a ElectricalConductance scalar.
196 * @param v scalar
197 * @return scalar as a division of Dimensionless and ElectricalResistance
198 */
199 public ElectricalConductance divide(final ElectricalResistance v)
200 {
201 return new ElectricalConductance(this.si() / v.si(), ElectricalConductance.Unit.SI);
202 }
203
204 @Override
205 public Dimensionless reciprocal()
206 {
207 return ofSi(1.0 / this.si());
208 }
209
210 }