12 public static Vector4
Frac(Vector4 vector_a)
14 vector_a.x = (float)((
double)vector_a.x -
System.Math.Truncate((
double)vector_a.x));
15 vector_a.y = (float)((
double)vector_a.y -
System.Math.Truncate((
double)vector_a.y));
16 vector_a.z = (float)((
double)vector_a.z -
System.Math.Truncate((
double)vector_a.z));
17 vector_a.w = (float)((
double)vector_a.w -
System.Math.Truncate((
double)vector_a.w));
25 Debug.LogError(
"Cannot encode float < -500 or > 500");
31 Vector4 kEncodeMul =
new Vector4(1.0f, 255.0f, 65535.0f, 16777215.0f);
32 float kEncodeBit = 1.0f / 255.0f;
33 Vector4 enc = kEncodeMul * v;
35 enc -=
new Vector4(enc.y, enc.z, enc.w, enc.w) * kEncodeBit;
55 number_float = number;
58 quotient_float = number_float * 2.0f;
59 if (quotient_float>=1.0f)
62 quotient_float -= 1.0f;
67 number_float = quotient_float;
69 if (quotient_float==0.0f)
77 number_int = (int)number;
80 quotient = (int)Mathf.Floor(number_int / 2);
81 reminder = (number_int-(quotient*2));
82 number_int = quotient;
97 s =
"0000000000000000000000000000000000000000000000" + s;
98 s = s.Substring(s.Length-padding);
115 return "00000000000000000000000000000000";
119 return "10000000000000000000000000000000";
121 if (
float.IsPositiveInfinity(f))
123 return "01111111100000000000000000000000";
125 if (
float.IsNegativeInfinity(f))
127 return "11111111100000000000000000000000";
131 return "11111111110000000000000000000000";
138 if (Mathf.Sign(f)>=0)
148 s = f.ToString(
"0.#############################");
150 is_significant =
true;
152 ca = s.ToCharArray();
164 if ((c==
'0') || (c==
'1') || (c==
'2') || (c==
'3') || (c==
'4') || (c==
'5') || (c==
'6') || (c==
'7') || (c==
'8') || (c==
'9'))
166 is_significant = (izero<0);
190 exponent = -(sf2bin.IndexOf(
"1")+1);
193 exponent = si2bin.Length-1;
198 biased_exponent = 127 + exponent;
200 sbe2bin =
"00000000" + sbe2bin;
201 sbe2bin = sbe2bin.Substring(sbe2bin.Length-8, 8);
202 string stotal = ss + sbe2bin;
205 last_index = sf2bin.LastIndexOf(
'1');
206 stotal += sf2bin.Substring(-exponent);
207 stotal +=
"0000000000000000000000000000000000000000000000";
210 stotal = stotal.Substring(0, 31) +
'1';
213 stotal = stotal.Substring(0, 32);
217 stotal += si2bin.Substring(1) + sf2bin;
218 if (stotal.Length>32)
220 stotal = stotal.Substring(0, 31) +
'1';
223 stotal +=
"0000000000000000000000000000000000000000000000";
224 stotal = stotal.Substring(0, 32);
232 Color cl = Color.black;
234 int len = b.Length-1;
243 for (
int i=len; 0<=i; i--)
248 ic += Mathf.Pow(2.0f, ii);
251 if ((ib==1) && (ii==8))
254 cl.a = Mathf.Floor(ic) / 255;
259 if ((ib==2) && (ii==8))
262 cl.b = Mathf.Floor(ic) / 255;
267 if ((ib==3) && (ii==8))
270 cl.g = Mathf.Floor(ic) / 255;
275 if ((ib==4) && (ii==8))
278 cl.r = Mathf.Floor(ic) / 255;
static Vector4 Frac(Vector4 vector_a)
static string IntToBinaryString(float number, bool fraction, int padding)
static Color BinaryStringToColor(string b)
static Vector4 EncodeFloatRGBA(float v)
static Color FloatToColor(float f)
static string FloatToBinaryString(float f)