| 1 |
#include "tads.h" |
| 2 |
#include "t3.h" |
| 3 |
#include "dict.h" |
| 4 |
#include "bignum.h" |
| 5 |
|
| 6 |
main(args) |
| 7 |
{ |
| 8 |
local x, y, z, lst; |
| 9 |
|
| 10 |
/* |
| 11 |
* creation tests |
| 12 |
*/ |
| 13 |
x = 3.1415927; |
| 14 |
y = 1234567890987654321.; |
| 15 |
y = 12345678909876543210.; |
| 16 |
y = new BigNumber(100, 10); |
| 17 |
y = new BigNumber(12345, 32); |
| 18 |
y = new BigNumber(123456, 33); |
| 19 |
|
| 20 |
/* |
| 21 |
* display tests |
| 22 |
*/ |
| 23 |
tadsSay(1234.5678); "\n"; |
| 24 |
tadsSay(x); "\n"; |
| 25 |
tadsSay(y); "\n"; |
| 26 |
tadsSay(123456789234567893456789456789567896789789899.); "\n"; |
| 27 |
tadsSay(100e-2000); "\n"; |
| 28 |
tadsSay(5.9999988888e5000); "\n"; |
| 29 |
tadsSay(12345e-20000); "\n"; |
| 30 |
tadsSay(1234e-8); "\n"; |
| 31 |
tadsSay(.090807); "\n"; |
| 32 |
"\b"; |
| 33 |
|
| 34 |
/* |
| 35 |
* string formatting tests |
| 36 |
*/ |
| 37 |
|
| 38 |
x = toString(.75e4); |
| 39 |
tadsSay(x); "\n"; |
| 40 |
"\b"; |
| 41 |
|
| 42 |
x = 1234.5362; |
| 43 |
"(4): <<x.formatString(4)>>\n"; |
| 44 |
"(5): <<x.formatString(5)>>\n"; |
| 45 |
"(6): <<x.formatString(6)>>\n"; |
| 46 |
"(7): <<x.formatString(7)>>\n"; |
| 47 |
"\b"; |
| 48 |
|
| 49 |
x = 999.99999; |
| 50 |
"(8): <<x.formatString(8)>>\n"; |
| 51 |
"(7): <<x.formatString(7)>>\n"; |
| 52 |
"(5): <<x.formatString(5)>>\n"; |
| 53 |
"(4): <<x.formatString(4)>>\n"; |
| 54 |
"(3): <<x.formatString(3)>>\n"; |
| 55 |
"(2): <<x.formatString(2)>>\n"; |
| 56 |
"(7,0,0,3): <<x.formatString(7, 0, 0, 3)>>\n"; |
| 57 |
"(7,0,0,5): <<x.formatString(7, 0, 0, 5)>>\n"; |
| 58 |
"(8,EXP): <<x.formatString(8, BignumExp)>>\n"; |
| 59 |
"(7,EXP): <<x.formatString(7, BignumExp)>>\n"; |
| 60 |
"(3,EXP+PT): <<x.formatString(3, BignumExp | BignumPoint)>>\n"; |
| 61 |
"(8,EXP,0,2): <<x.formatString(8, BignumExp, 0, 2)>>\n"; |
| 62 |
"(10,0,7,5): <<x.formatString(10, 0, 7, 5)>>\n"; |
| 63 |
"(10,0,7,3): <<x.formatString(10, 0, 7, 3)>>\n"; |
| 64 |
|
| 65 |
"(15,0,12,3,0,'*'): <<x.formatString(15, 0, 12, 3, 0, '*')>>\n"; |
| 66 |
"(15,0,12,3,0,'/*\\*'): <<x.formatString(15, 0, 12, 3, 0, '/*\\*')>>\n"; |
| 67 |
"(15,COMMAS,12,3,0,'/*\\*'): |
| 68 |
<<x.formatString(15, BignumCommas, 12, 3, 0, '/*\\*')>>\n"; |
| 69 |
|
| 70 |
x = 12345.6789; |
| 71 |
"(15,COMMAS,12,3,0,'/*\\*'): |
| 72 |
<<x.formatString(15, BignumCommas, 12, 3, 0, '/*\\*')>>\n"; |
| 73 |
|
| 74 |
x = 1234567.8900; |
| 75 |
"(15,COMMAS,12,3,0,'/*\\*'): |
| 76 |
<<x.formatString(15, BignumCommas, 12, 3, 0, '/*\\*')>>\n"; |
| 77 |
|
| 78 |
x = 12345678.8900; |
| 79 |
"(15,COMMAS,12,3,0,'/*\\*'): |
| 80 |
<<x.formatString(15, BignumCommas, 12, 3, 0, '/*\\*')>>\n"; |
| 81 |
|
| 82 |
x = 12345678.98765; |
| 83 |
"(20,COMMAS): <<x.formatString(20, BignumCommas)>>\n"; |
| 84 |
"(20,COMMAS+EURO): |
| 85 |
<<x.formatString(20, BignumCommas | BignumEuroStyle)>>\n"; |
| 86 |
"(20 - no space):<<x.formatString(20)>>\n"; |
| 87 |
"(20,POS_SPACE):<<x.formatString(20, BignumPosSpace)>>\n"; |
| 88 |
|
| 89 |
x = 123456789.98765; |
| 90 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 91 |
|
| 92 |
x = .00098765; |
| 93 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 94 |
x = 0.98765; |
| 95 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 96 |
x = 1.98765; |
| 97 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 98 |
x = 12.98765; |
| 99 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 100 |
x = 123.98765; |
| 101 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 102 |
x = 1234.98765; |
| 103 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 104 |
x = 12345.98765; |
| 105 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 106 |
x = 123456.98765; |
| 107 |
"(20,COMMAS):<<x.formatString(20, BignumCommas)>>\n"; |
| 108 |
"\b"; |
| 109 |
|
| 110 |
/* |
| 111 |
* Zero formatting tests |
| 112 |
*/ |
| 113 |
|
| 114 |
x = 0.; |
| 115 |
"zero: <<x>>\n"; |
| 116 |
"(3,EXP): <<x.formatString(3, BignumExp)>>\n"; |
| 117 |
"(8,EXP+PT): <<x.formatString(8, BignumExp | BignumPoint)>>\n"; |
| 118 |
"(8,EXP,0,2): <<x.formatString(8, BignumExp, 0, 2)>>\n"; |
| 119 |
"\b"; |
| 120 |
|
| 121 |
/* |
| 122 |
* equality comparison tests |
| 123 |
*/ |
| 124 |
|
| 125 |
x = 123.456; |
| 126 |
y = 123.45600001; |
| 127 |
"x = <<x>>, y = <<y>>\n"; |
| 128 |
"(equal exact): <<x == y ? 'yes' : 'no'>>\n"; |
| 129 |
"(equal with rounding): <<x.equalRound(y) ? 'yes' : 'no'>>\n"; |
| 130 |
|
| 131 |
x = 123.456; |
| 132 |
y = 1.23456e2; |
| 133 |
"x = <<x>>, y = <<y>>\n"; |
| 134 |
"(equal exact): <<x == y ? 'yes' : 'no'>>\n"; |
| 135 |
"(equal with rounding): <<x.equalRound(y) ? 'yes' : 'no'>>\n"; |
| 136 |
|
| 137 |
x = 100.; |
| 138 |
y = 99.999; |
| 139 |
"x = <<x>>, y = <<y>>\n"; |
| 140 |
"(equal exact): <<x == y ? 'yes' : 'no'>>\n"; |
| 141 |
"(equal with rounding): <<x.equalRound(y) ? 'yes' : 'no'>>\n"; |
| 142 |
|
| 143 |
x = 100.001; |
| 144 |
y = 100.002; |
| 145 |
"x = <<x>>, y = <<y>>\n"; |
| 146 |
"(equal exact): <<x == y ? 'yes' : 'no'>>\n"; |
| 147 |
"(equal with rounding): <<x.equalRound(y) ? 'yes' : 'no'>>\n"; |
| 148 |
"\b"; |
| 149 |
|
| 150 |
/* |
| 151 |
* Magnitude comparison tests |
| 152 |
*/ |
| 153 |
|
| 154 |
x = 123.456; |
| 155 |
y = 123.4561; |
| 156 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 157 |
|
| 158 |
x = 123.456; |
| 159 |
y = -123.4561; |
| 160 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 161 |
|
| 162 |
x = -123.4561; |
| 163 |
y = 123.4560; |
| 164 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 165 |
|
| 166 |
x = -123.456; |
| 167 |
y = -123.4561; |
| 168 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 169 |
|
| 170 |
x = 999.; |
| 171 |
y = .999; |
| 172 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 173 |
|
| 174 |
x = -999.; |
| 175 |
y = -.999; |
| 176 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 177 |
|
| 178 |
x = 1.; |
| 179 |
y = 2.; |
| 180 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 181 |
|
| 182 |
x = 111.01; |
| 183 |
y = 111.10; |
| 184 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 185 |
|
| 186 |
x = 0.0000; |
| 187 |
y = 35.3; |
| 188 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 189 |
|
| 190 |
x = -32.000; |
| 191 |
y = 0.000; |
| 192 |
"x = <<x>>, y = <<y>>, x < y = <<bool(x<y)>>, x > y = <<bool(x>y)>>\n"; |
| 193 |
|
| 194 |
"\b"; |
| 195 |
|
| 196 |
/* |
| 197 |
* Get/Set-Precision tests |
| 198 |
*/ |
| 199 |
|
| 200 |
x = 1234567890.; |
| 201 |
"x = <<x>>, x.getPrecision() = <<x.getPrecision()>>, |
| 202 |
x.setPrecision(5) = <<x.setPrecision(5)>>, "; |
| 203 |
|
| 204 |
"x.setPrecision(3) = <<x.setPrecision(3)>>\n"; |
| 205 |
|
| 206 |
"x.setPrecision(15) = <<x.setPrecision(15)>>\n"; |
| 207 |
"\b"; |
| 208 |
|
| 209 |
/* |
| 210 |
* Addition and subtraction tests |
| 211 |
*/ |
| 212 |
|
| 213 |
x = 12345.6789; |
| 214 |
y = 3.14159265; |
| 215 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 216 |
|
| 217 |
x = 1.999999; |
| 218 |
y = 2.001; |
| 219 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 220 |
|
| 221 |
x = 1200.; |
| 222 |
y = .0533; |
| 223 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 224 |
|
| 225 |
x = 1200.; |
| 226 |
y = .5335; |
| 227 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 228 |
|
| 229 |
x = 9999.; |
| 230 |
y = .5335; |
| 231 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x+y+1 = <<x+y+1>>\n"; |
| 232 |
"x-y = <<x-y>>\n"; |
| 233 |
|
| 234 |
x = 9999.; |
| 235 |
y = .4999; |
| 236 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x+y+1 = <<x+y+1>>\n"; |
| 237 |
"x-y = <<x-y>>\n"; |
| 238 |
|
| 239 |
x = 9999.; |
| 240 |
y = 1.999; |
| 241 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 242 |
|
| 243 |
x = 9999.; |
| 244 |
y = 9.999; |
| 245 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 246 |
|
| 247 |
x = 9999.; |
| 248 |
y = 5.999; |
| 249 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 250 |
|
| 251 |
x = 9999.; |
| 252 |
y = 6.999; |
| 253 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 254 |
|
| 255 |
x = 9999.; |
| 256 |
y = 3.999; |
| 257 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 258 |
|
| 259 |
x = 1234.; |
| 260 |
y = -5678.; |
| 261 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 262 |
|
| 263 |
x = -1234.; |
| 264 |
y = 5678.; |
| 265 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 266 |
|
| 267 |
x = 1000.1; |
| 268 |
y = .0001; |
| 269 |
"x = <<x>>, y = <<y>>, x+y = <<x+y>>, x-y = <<x-y>>\n"; |
| 270 |
|
| 271 |
"\b"; |
| 272 |
|
| 273 |
/* |
| 274 |
* Multiplication |
| 275 |
*/ |
| 276 |
x = 1.; |
| 277 |
y = 1.00001; |
| 278 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 279 |
|
| 280 |
x = 3456.; |
| 281 |
y = 3.; |
| 282 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 283 |
|
| 284 |
x = 1234.; |
| 285 |
y = 5678.; |
| 286 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 287 |
|
| 288 |
x = 1.999; |
| 289 |
y = 9.99; |
| 290 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 291 |
|
| 292 |
x = 3.14159265; |
| 293 |
y = 0.25; |
| 294 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 295 |
|
| 296 |
x = 8751.; |
| 297 |
y = 1.1110000; |
| 298 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 299 |
|
| 300 |
x = 8751.; |
| 301 |
y = 1.111; |
| 302 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 303 |
|
| 304 |
x = 8751.; |
| 305 |
y = 9.0009; |
| 306 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 307 |
|
| 308 |
x = 8751.; |
| 309 |
y = 9.000009; |
| 310 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 311 |
|
| 312 |
x = -3883.1; |
| 313 |
y = 57.6010199; |
| 314 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 315 |
|
| 316 |
x = 42.7; |
| 317 |
y = -177.; |
| 318 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 319 |
|
| 320 |
x = -.979; |
| 321 |
y = -3.203; |
| 322 |
"x = <<x>>, y = <<y>>, x*y = <<x*y>>\n"; |
| 323 |
|
| 324 |
"\b"; |
| 325 |
|
| 326 |
/* |
| 327 |
* Division |
| 328 |
*/ |
| 329 |
|
| 330 |
x = -.979; |
| 331 |
y = -3.203; |
| 332 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 333 |
|
| 334 |
x = 32.; |
| 335 |
y = 522.; |
| 336 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 337 |
|
| 338 |
x = 7205.; |
| 339 |
y = 3.; |
| 340 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 341 |
|
| 342 |
x = 1.; |
| 343 |
y = 1.00001; |
| 344 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 345 |
|
| 346 |
x = 3456.; |
| 347 |
y = 3.; |
| 348 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 349 |
|
| 350 |
x = 1234.; |
| 351 |
y = 5678.; |
| 352 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 353 |
|
| 354 |
x = 1.999; |
| 355 |
y = 9.99; |
| 356 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 357 |
|
| 358 |
x = 3.14159265; |
| 359 |
y = 0.25; |
| 360 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 361 |
|
| 362 |
x = 8751.; |
| 363 |
y = 1.1110000; |
| 364 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 365 |
|
| 366 |
x = 8751.; |
| 367 |
y = 1.111; |
| 368 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 369 |
|
| 370 |
x = 8751.; |
| 371 |
y = 9.0009; |
| 372 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 373 |
|
| 374 |
x = 8751.; |
| 375 |
y = 9.000009; |
| 376 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 377 |
|
| 378 |
x = -3883.1; |
| 379 |
y = 57.6010199; |
| 380 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 381 |
|
| 382 |
x = 42.7; |
| 383 |
y = -177.; |
| 384 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 385 |
|
| 386 |
x = -.979; |
| 387 |
y = -3.203; |
| 388 |
"x = <<x>>, y = <<y>>, x/y = <<x/y>>\n"; |
| 389 |
|
| 390 |
/* |
| 391 |
* Remainders |
| 392 |
*/ |
| 393 |
|
| 394 |
x = 12345.; |
| 395 |
y = 77.; |
| 396 |
lst = x.divideBy(y); |
| 397 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 398 |
|
| 399 |
x = 12397.; |
| 400 |
y = 77.; |
| 401 |
lst = x.divideBy(y); |
| 402 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 403 |
|
| 404 |
x = 12396.; |
| 405 |
y = 77.; |
| 406 |
lst = x.divideBy(y); |
| 407 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 408 |
|
| 409 |
x = 77.; |
| 410 |
y = 123.; |
| 411 |
lst = x.divideBy(y); |
| 412 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 413 |
|
| 414 |
x = -12345.; |
| 415 |
y = 77.; |
| 416 |
lst = x.divideBy(y); |
| 417 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 418 |
|
| 419 |
x = 12345.; |
| 420 |
y = -77.; |
| 421 |
lst = x.divideBy(y); |
| 422 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 423 |
|
| 424 |
x = -12345.; |
| 425 |
y = -77.; |
| 426 |
lst = x.divideBy(y); |
| 427 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 428 |
|
| 429 |
x = -10.; |
| 430 |
y = -3.; |
| 431 |
lst = x.divideBy(y); |
| 432 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 433 |
|
| 434 |
x = 123e5; |
| 435 |
y = 77.; |
| 436 |
lst = x.divideBy(y); |
| 437 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 438 |
|
| 439 |
x = 0.000; |
| 440 |
y = 77.; |
| 441 |
lst = x.divideBy(y); |
| 442 |
"x = <<x>>, y = <<y>>, x/y = <<lst[1]>>, x mod y = <<lst[2]>>\n"; |
| 443 |
|
| 444 |
"\b"; |
| 445 |
|
| 446 |
/* |
| 447 |
* Fraction/Whole tests |
| 448 |
*/ |
| 449 |
|
| 450 |
x = 1234.5678; |
| 451 |
"x = <<x>>, frac = <<x.getFraction()>>, whole = <<x.getWhole()>>\n"; |
| 452 |
|
| 453 |
x = .9325773; |
| 454 |
"x = <<x>>, frac = <<x.getFraction()>>, whole = <<x.getWhole()>>\n"; |
| 455 |
|
| 456 |
x = 8.710243; |
| 457 |
"x = <<x>>, frac = <<x.getFraction()>>, whole = <<x.getWhole()>>\n"; |
| 458 |
|
| 459 |
x = 1.234e-15; |
| 460 |
"x = <<x>>, frac = <<x.getFraction()>>, whole = <<x.getWhole()>>\n"; |
| 461 |
|
| 462 |
x = 1234567800000000.; |
| 463 |
"x = <<x>>, frac = <<x.getFraction()>>, whole = <<x.getWhole()>>\n"; |
| 464 |
|
| 465 |
"\b"; |
| 466 |
|
| 467 |
/* |
| 468 |
* RoundToDecimal tests |
| 469 |
*/ |
| 470 |
|
| 471 |
x = 1234.53739; |
| 472 |
"x = <<x>>, round(0) = <<x.roundToDecimal(0)>>\n |
| 473 |
... round(1) = <<x.roundToDecimal(1)>>\n |
| 474 |
... round(2) = <<x.roundToDecimal(2)>>\n |
| 475 |
... round(3) = <<x.roundToDecimal(3)>>\n |
| 476 |
... round(4) = <<x.roundToDecimal(4)>>\n |
| 477 |
... round(5) = <<x.roundToDecimal(5)>>\n |
| 478 |
... round(6) = <<x.roundToDecimal(6)>>\n |
| 479 |
... round(7) = <<x.roundToDecimal(7)>>\n |
| 480 |
... round(22) = <<x.roundToDecimal(22)>>\n |
| 481 |
... round(-1) = <<x.roundToDecimal(-1)>>\n |
| 482 |
... round(-2) = <<x.roundToDecimal(-2)>>\n |
| 483 |
... round(-3) = <<x.roundToDecimal(-3)>>\n |
| 484 |
... round(-4) = <<x.roundToDecimal(-4)>>\n |
| 485 |
... round(-5) = <<x.roundToDecimal(-5)>>\n |
| 486 |
... round(-10) = <<x.roundToDecimal(-10)>>\n"; |
| 487 |
x = 9999.99999; |
| 488 |
"x = <<x>>, round(0) = <<x.roundToDecimal(0)>>\n |
| 489 |
... round(1) = <<x.roundToDecimal(1)>>\n |
| 490 |
... round(2) = <<x.roundToDecimal(2)>>\n |
| 491 |
... round(3) = <<x.roundToDecimal(3)>>\n |
| 492 |
... round(4) = <<x.roundToDecimal(4)>>\n |
| 493 |
... round(5) = <<x.roundToDecimal(5)>>\n |
| 494 |
... round(6) = <<x.roundToDecimal(6)>>\n |
| 495 |
... round(7) = <<x.roundToDecimal(7)>>\n |
| 496 |
... round(22) = <<x.roundToDecimal(22)>>\n |
| 497 |
... round(-1) = <<x.roundToDecimal(-1)>>\n |
| 498 |
... round(-2) = <<x.roundToDecimal(-2)>>\n |
| 499 |
... round(-3) = <<x.roundToDecimal(-3)>>\n |
| 500 |
... round(-4) = <<x.roundToDecimal(-4)>>\n |
| 501 |
... round(-5) = <<x.roundToDecimal(-5)>>\n |
| 502 |
... round(-10) = <<x.roundToDecimal(-10)>>\n"; |
| 503 |
|
| 504 |
"\b"; |
| 505 |
|
| 506 |
/* |
| 507 |
* abs, floor, ceil tests |
| 508 |
*/ |
| 509 |
x = 0.1234; |
| 510 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 511 |
floor(x) = <<x.getFloor()>>\n"; |
| 512 |
|
| 513 |
x = -0.1234; |
| 514 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 515 |
floor(x) = <<x.getFloor()>>\n"; |
| 516 |
|
| 517 |
x = 7.1234; |
| 518 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 519 |
floor(x) = <<x.getFloor()>>\n"; |
| 520 |
|
| 521 |
x = -7.1234; |
| 522 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 523 |
floor(x) = <<x.getFloor()>>\n"; |
| 524 |
|
| 525 |
x = 0.0000; |
| 526 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 527 |
floor(x) = <<x.getFloor()>>\n"; |
| 528 |
|
| 529 |
x = 1.4e-5; |
| 530 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 531 |
floor(x) = <<x.getFloor()>>\n"; |
| 532 |
|
| 533 |
x = -1.4e-5; |
| 534 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 535 |
floor(x) = <<x.getFloor()>>\n"; |
| 536 |
|
| 537 |
x = 999.9999; |
| 538 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 539 |
floor(x) = <<x.getFloor()>>\n"; |
| 540 |
|
| 541 |
x = -999.9999; |
| 542 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 543 |
floor(x) = <<x.getFloor()>>\n"; |
| 544 |
|
| 545 |
x = 999.0000000001; |
| 546 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 547 |
floor(x) = <<x.getFloor()>>\n"; |
| 548 |
|
| 549 |
x = -999.0000000001; |
| 550 |
"x = <<x>>, abs(x) = <<x.getAbs()>>, ceil(x) = <<x.getCeil()>>, |
| 551 |
floor(x) = <<x.getFloor()>>\n"; |
| 552 |
|
| 553 |
"\b"; |
| 554 |
|
| 555 |
/* |
| 556 |
* scaleTen tets |
| 557 |
*/ |
| 558 |
|
| 559 |
x = 12345.; |
| 560 |
for (local i = -5 ; i <= 5 ; ++i) |
| 561 |
"x = <<x>>, x.scaleTen(<<i>>) = <<x.scaleTen(i)>>\n"; |
| 562 |
|
| 563 |
"x.getScale() = <<x.getScale()>>\n"; |
| 564 |
for (local i = -5 ; i <= 5 ; ++i) |
| 565 |
"x.scaleTen(<<i>>).getScale() = <<x.scaleTen(i).getScale()>>\n"; |
| 566 |
|
| 567 |
"\b"; |
| 568 |
|
| 569 |
/* |
| 570 |
* negate tests |
| 571 |
*/ |
| 572 |
x = 0.; |
| 573 |
"x = <<x>>, x.negate() = <<x.negate()>>\n"; |
| 574 |
|
| 575 |
x = 123.; |
| 576 |
"x = <<x>>, x.negate() = <<x.negate()>>\n"; |
| 577 |
|
| 578 |
x = 0.123; |
| 579 |
"x = <<x>>, x.negate() = <<x.negate()>>\n"; |
| 580 |
|
| 581 |
x = -0.123; |
| 582 |
"x = <<x>>, x.negate() = <<x.negate()>>\n"; |
| 583 |
|
| 584 |
x = -987.; |
| 585 |
"x = <<x>>, x.negate() = <<x.negate()>>\n"; |
| 586 |
|
| 587 |
x = -987.; |
| 588 |
"x = <<x>>, -x = <<-x>>\n"; |
| 589 |
|
| 590 |
x = 123.456; |
| 591 |
"x = <<x>>, -x = <<-x>>\n"; |
| 592 |
|
| 593 |
"\b"; |
| 594 |
|
| 595 |
/* |
| 596 |
* copySignFrom tests |
| 597 |
*/ |
| 598 |
x = 123.; |
| 599 |
y = .345; |
| 600 |
"x = <<x>>, y = <<y>>, x.copySignFrom(y) = <<x.copySignFrom(y)>>\n"; |
| 601 |
|
| 602 |
x = 123.; |
| 603 |
y = -.345; |
| 604 |
"x = <<x>>, y = <<y>>, x.copySignFrom(y) = <<x.copySignFrom(y)>>\n"; |
| 605 |
|
| 606 |
x = -123.; |
| 607 |
y = .345; |
| 608 |
"x = <<x>>, y = <<y>>, x.copySignFrom(y) = <<x.copySignFrom(y)>>\n"; |
| 609 |
|
| 610 |
x = -123.; |
| 611 |
y = -.345; |
| 612 |
"x = <<x>>, y = <<y>>, x.copySignFrom(y) = <<x.copySignFrom(y)>>\n"; |
| 613 |
|
| 614 |
x = 0.; |
| 615 |
y = .345; |
| 616 |
"x = <<x>>, y = <<y>>, x.copySignFrom(y) = <<x.copySignFrom(y)>>\n"; |
| 617 |
|
| 618 |
x = 0.; |
| 619 |
y = -3.345; |
| 620 |
"x = <<x>>, y = <<y>>, x.copySignFrom(y) = <<x.copySignFrom(y)>>\n"; |
| 621 |
|
| 622 |
"\b"; |
| 623 |
|
| 624 |
/* |
| 625 |
* IsNegative tests |
| 626 |
*/ |
| 627 |
|
| 628 |
x = 0.; |
| 629 |
"x = <<x>>, x.isNegative = <<x.isNegative() ? 'yes' : 'no'>>\n"; |
| 630 |
|
| 631 |
x = 123.; |
| 632 |
"x = <<x>>, x.isNegative = <<x.isNegative() ? 'yes' : 'no'>>\n"; |
| 633 |
|
| 634 |
x = -123.; |
| 635 |
"x = <<x>>, x.isNegative = <<x.isNegative() ? 'yes' : 'no'>>\n"; |
| 636 |
|
| 637 |
x = 0.005; |
| 638 |
"x = <<x>>, x.isNegative = <<x.isNegative() ? 'yes' : 'no'>>\n"; |
| 639 |
|
| 640 |
x = -0.005; |
| 641 |
"x = <<x>>, x.isNegative = <<x.isNegative() ? 'yes' : 'no'>>\n"; |
| 642 |
|
| 643 |
"\b"; |
| 644 |
|
| 645 |
/* |
| 646 |
* toInteger tests |
| 647 |
*/ |
| 648 |
|
| 649 |
x = 0.; |
| 650 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 651 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 652 |
|
| 653 |
x = 123.; |
| 654 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 655 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 656 |
|
| 657 |
x = 0.456; |
| 658 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 659 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 660 |
|
| 661 |
x = 0.567; |
| 662 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 663 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 664 |
|
| 665 |
x = 987.568; |
| 666 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 667 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 668 |
|
| 669 |
x = 893.499; |
| 670 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 671 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 672 |
|
| 673 |
x = 2147483646.299; |
| 674 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 675 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 676 |
|
| 677 |
x = 2147483646.832; |
| 678 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 679 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 680 |
|
| 681 |
x = 2147483647.299; |
| 682 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 683 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 684 |
|
| 685 |
x = 2147483647.832; |
| 686 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 687 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 688 |
|
| 689 |
x = -2147483647.200; |
| 690 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 691 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 692 |
|
| 693 |
x = -2147483647.822; |
| 694 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 695 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 696 |
|
| 697 |
x = -2147483648.200; |
| 698 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 699 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 700 |
|
| 701 |
x = -2147483648.822; |
| 702 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 703 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 704 |
|
| 705 |
x = 9999999999.200; |
| 706 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 707 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 708 |
|
| 709 |
x = -9999999999.200; |
| 710 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 711 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 712 |
|
| 713 |
x = 2149.7483647200; |
| 714 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 715 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 716 |
|
| 717 |
x = -2149.7483647200; |
| 718 |
try { "x = <<x>>, toInteger(x) = <<toInteger(x)>>\n"; } |
| 719 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 720 |
|
| 721 |
"\b"; |
| 722 |
|
| 723 |
/* |
| 724 |
* Sine |
| 725 |
*/ |
| 726 |
x = 0.785398164; // pi/4 -> .707106782 |
| 727 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 728 |
|
| 729 |
x = 1.57079633; // pi/2 -> 1.0000000 |
| 730 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 731 |
|
| 732 |
x = 3.14159265; // pi -> 0 |
| 733 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 734 |
|
| 735 |
x = 1.11111; // -> 0.896192 |
| 736 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 737 |
|
| 738 |
x = 2.0000; // -> 0.909297 -> .90930 |
| 739 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 740 |
|
| 741 |
x = 3.010203; // -> .1310119 |
| 742 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 743 |
|
| 744 |
x = 4.567890; // -> -.9895782 |
| 745 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 746 |
|
| 747 |
x = 5.43210; // -> -.751996 |
| 748 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 749 |
|
| 750 |
x = 6.012345; // -> -.2675412 |
| 751 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 752 |
|
| 753 |
x = 6.305555; // a little over 2pi -> .02236783 |
| 754 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 755 |
|
| 756 |
x = 9.350123; // -> 0.07458563 |
| 757 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 758 |
|
| 759 |
x = -0.785398164; // -pi/4 -> -.707106782 |
| 760 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 761 |
|
| 762 |
x = -1.57079633; // -pi/2 -> -1.0000000 |
| 763 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 764 |
|
| 765 |
x = -3.14159265; // -pi -> 0 |
| 766 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 767 |
|
| 768 |
x = -1.11111; // -> -0.896192 |
| 769 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 770 |
|
| 771 |
x = -2.0000; // -> -0.909297 -> -.90930 |
| 772 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 773 |
|
| 774 |
x = -3.010203; // -> -.1310119 |
| 775 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 776 |
|
| 777 |
x = -4.567890; // -> .9895782 |
| 778 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 779 |
|
| 780 |
x = -5.43210; // -> .751996 |
| 781 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 782 |
|
| 783 |
x = -6.012345; // -> .2675412 |
| 784 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 785 |
|
| 786 |
x = -6.305555; // a little over -2pi -> -.02236783 |
| 787 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 788 |
|
| 789 |
x = -9.350123; // -> -0.07458563 |
| 790 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 791 |
|
| 792 |
x = 0.00000000; // -> .00000000 |
| 793 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 794 |
|
| 795 |
x = 0.50000000; // -> .47942554 |
| 796 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 797 |
|
| 798 |
x = 112.; // -> -0.88999560 -> -0.89 |
| 799 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 800 |
|
| 801 |
x = 112000.; // -> 0.79541568 |
| 802 |
"x = <<x>>, sin(x) = <<x.sine()>>\n"; |
| 803 |
|
| 804 |
"\b"; |
| 805 |
|
| 806 |
/* |
| 807 |
* Cosine |
| 808 |
*/ |
| 809 |
x = 0.785398164; // pi/4 -> 0.707106781 |
| 810 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 811 |
|
| 812 |
x = 1.57079633; // pi/2 -> 0 |
| 813 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 814 |
|
| 815 |
x = 3.14159265; // pi -> -1 |
| 816 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 817 |
|
| 818 |
x = 1.11111; // -> .443667 |
| 819 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 820 |
|
| 821 |
x = 2.0000; // -> -0.41615 |
| 822 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 823 |
|
| 824 |
x = 3.010203; // -> -.9913808 |
| 825 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 826 |
|
| 827 |
x = 4.567890; // -> -.1439967 |
| 828 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 829 |
|
| 830 |
x = 5.43210; // -> .659167 |
| 831 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 832 |
|
| 833 |
x = 6.012345; // -> .9635464 |
| 834 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 835 |
|
| 836 |
x = 6.305555; // a little over 2pi -> .9997498 |
| 837 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 838 |
|
| 839 |
x = 9.350123; // -> -.9972146 |
| 840 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 841 |
|
| 842 |
x = -0.785398164; // -pi/4 -> .707106781 |
| 843 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 844 |
|
| 845 |
x = -1.57079633; // -pi/2 -> 0 |
| 846 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 847 |
|
| 848 |
x = -3.14159265; // -pi -> -1 |
| 849 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 850 |
|
| 851 |
x = -1.11111; // -> 0.443667 |
| 852 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 853 |
|
| 854 |
x = -2.0000; // -> -.41615 |
| 855 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 856 |
|
| 857 |
x = -3.010203; // -> -.9913808 |
| 858 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 859 |
|
| 860 |
x = -4.567890; // -> -.1439967 |
| 861 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 862 |
|
| 863 |
x = -5.43210; // -> .659167 |
| 864 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 865 |
|
| 866 |
x = -6.012345; // -> .9635464 |
| 867 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 868 |
|
| 869 |
x = -6.305555; // a little over -2pi -> .9997498 |
| 870 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 871 |
|
| 872 |
x = -9.350123; // -> -.9972146 |
| 873 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 874 |
|
| 875 |
x = 0.00000000; // -> 1 |
| 876 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 877 |
|
| 878 |
x = 0.50000000; // -> .87758256 |
| 879 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 880 |
|
| 881 |
x = 112.; // -> .456 |
| 882 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 883 |
|
| 884 |
x = 112000.; // -> -.606064 |
| 885 |
"x = <<x>>, cos(x) = <<x.cosine()>>\n"; |
| 886 |
|
| 887 |
"\b"; |
| 888 |
|
| 889 |
/* |
| 890 |
* Tangent |
| 891 |
*/ |
| 892 |
x = 0.785398164; // pi/4 -> 1 |
| 893 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 894 |
|
| 895 |
x = 1.57079633; // pi/2 -> -312012480.5 (really -INF) |
| 896 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 897 |
|
| 898 |
x = 3.14159265; // pi -> 0 |
| 899 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 900 |
|
| 901 |
x = 1.11111; // -> 2.01996 |
| 902 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 903 |
|
| 904 |
x = 2.0000; // -> -2.1850 |
| 905 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 906 |
|
| 907 |
x = 3.010203; // -> -.1321510 |
| 908 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 909 |
|
| 910 |
x = 4.567890; // -> 6.872231 |
| 911 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 912 |
|
| 913 |
x = 5.43210; // -> -1.14083 |
| 914 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 915 |
|
| 916 |
x = 6.012345; // -> -.2776630 |
| 917 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 918 |
|
| 919 |
x = 6.305555; // a little over 2pi -> .02237342 |
| 920 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 921 |
|
| 922 |
x = 9.350123; // -> -.07479396 |
| 923 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 924 |
|
| 925 |
x = -0.785398164; // -pi/4 -> -1 |
| 926 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 927 |
|
| 928 |
x = -1.57079633; // -pi/2 -> 312012480.5 (really +INF) |
| 929 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 930 |
|
| 931 |
x = -3.14159265; // -pi -> 0 |
| 932 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 933 |
|
| 934 |
x = -1.11111; // -> -2.01996 |
| 935 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 936 |
|
| 937 |
x = -2.0000; // -> 2.1850 |
| 938 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 939 |
|
| 940 |
x = -3.010203; // -> .1321510 |
| 941 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 942 |
|
| 943 |
x = -4.567890; // -> -6.872231 |
| 944 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 945 |
|
| 946 |
x = -5.43210; // -> 1.14083 |
| 947 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 948 |
|
| 949 |
x = -6.012345; // -> .2776630 |
| 950 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 951 |
|
| 952 |
x = -6.305555; // a little over -2pi -> -.02237342 |
| 953 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 954 |
|
| 955 |
x = -9.350123; // -> 0.07479396 |
| 956 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 957 |
|
| 958 |
x = 0.00000000; // -> 0 |
| 959 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 960 |
|
| 961 |
x = 0.50000000; // -> 0.54630249 |
| 962 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 963 |
|
| 964 |
x = 112.; // -> -1.95 |
| 965 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 966 |
|
| 967 |
x = 112000.; // -> -1.31243 |
| 968 |
"x = <<x>>, tan(x) = <<x.tangent()>>\n"; |
| 969 |
|
| 970 |
"\b"; |
| 971 |
|
| 972 |
/* |
| 973 |
* Radian/degree conversions |
| 974 |
*/ |
| 975 |
|
| 976 |
x = 90.0000; |
| 977 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 978 |
|
| 979 |
x = 180.000; |
| 980 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 981 |
|
| 982 |
x = 270.000; |
| 983 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 984 |
|
| 985 |
x = 360.000; |
| 986 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 987 |
|
| 988 |
x = 0.00000; |
| 989 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 990 |
|
| 991 |
x = -90.0000; |
| 992 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 993 |
|
| 994 |
x = -180.000; |
| 995 |
"x = <<x>>, d2r = <<x.degreesToRadians()>>\n"; |
| 996 |
|
| 997 |
x = 3.14159265; |
| 998 |
"x = <<x>>, r2d = <<x.radiansToDegrees()>>\n"; |
| 999 |
|
| 1000 |
x = -3.14159265; |
| 1001 |
"x = <<x>>, r2d = <<x.radiansToDegrees()>>\n"; |
| 1002 |
|
| 1003 |
x = 0.00000; |
| 1004 |
"x = <<x>>, r2d = <<x.radiansToDegrees()>>\n"; |
| 1005 |
|
| 1006 |
x = 1.57079633; |
| 1007 |
"x = <<x>>, r2d = <<x.radiansToDegrees()>>\n"; |
| 1008 |
|
| 1009 |
x = -1.57079633; |
| 1010 |
"x = <<x>>, r2d = <<x.radiansToDegrees()>>\n"; |
| 1011 |
|
| 1012 |
"\b"; |
| 1013 |
|
| 1014 |
/* |
| 1015 |
* arcsin/arccos |
| 1016 |
*/ |
| 1017 |
x = 0.0000000; // 0, 1.57079633 |
| 1018 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1019 |
|
| 1020 |
x = 0.50000000; // 0.52359878, 1.04719755 |
| 1021 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1022 |
|
| 1023 |
x = -0.50000000; // -.52359878, 2.09439510 |
| 1024 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1025 |
|
| 1026 |
x = 0.54030231; // 0.57079633, 1 |
| 1027 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1028 |
|
| 1029 |
x = -0.54030231; // -0.57079633, 2.14159266 |
| 1030 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1031 |
|
| 1032 |
x = 0.70710678; // 0.78539816, 0.78539816 |
| 1033 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1034 |
|
| 1035 |
x = 0.84147098; // 1, 0.57079633 |
| 1036 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1037 |
|
| 1038 |
x = 0.9000000; // 1.11976952, .45102681 |
| 1039 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1040 |
|
| 1041 |
x = 0.9999990; // 1.56938211, .00141421 |
| 1042 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1043 |
|
| 1044 |
x = -0.9999990; // -1.56938211, 3.14017844 |
| 1045 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1046 |
|
| 1047 |
x = 1.0000000; // 1.57079633, 0 |
| 1048 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1049 |
|
| 1050 |
x = -1.0000000; // -1.57079633, 3.14159265 |
| 1051 |
"x = <<x>>, asin = <<x.arcsine()>>, acos = <<x.arccosine()>>\n"; |
| 1052 |
|
| 1053 |
"\b"; |
| 1054 |
|
| 1055 |
/* |
| 1056 |
* arctan |
| 1057 |
*/ |
| 1058 |
x = 0.0000000; |
| 1059 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1060 |
|
| 1061 |
x = 1.2345678e-4; |
| 1062 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1063 |
|
| 1064 |
x = -1.2345678e-4; |
| 1065 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1066 |
|
| 1067 |
x = 0.2500000; |
| 1068 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1069 |
|
| 1070 |
x = -0.2500000; |
| 1071 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1072 |
|
| 1073 |
x = 1.0000000; |
| 1074 |
"x = <<x>>, atan = <<x.arctangent()>>, atan(1)*4 = |
| 1075 |
<<x.arctangent() * 4>>\n"; |
| 1076 |
|
| 1077 |
x = -1.0000000; |
| 1078 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1079 |
|
| 1080 |
x = 3.14159265; |
| 1081 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1082 |
|
| 1083 |
x = -3.14159265; |
| 1084 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1085 |
|
| 1086 |
x = 123.45678; |
| 1087 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1088 |
|
| 1089 |
x = -123.45678; |
| 1090 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1091 |
|
| 1092 |
x = 9876.54321; |
| 1093 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1094 |
|
| 1095 |
x = -9876.54321; |
| 1096 |
"x = <<x>>, atan = <<x.arctangent()>>\n"; |
| 1097 |
|
| 1098 |
"\b"; |
| 1099 |
|
| 1100 |
/* |
| 1101 |
* square root |
| 1102 |
*/ |
| 1103 |
x = 1234.5678; |
| 1104 |
"x = <<x>>, sqrt = <<x.sqrt()>>\n"; |
| 1105 |
|
| 1106 |
x = 12345.678; |
| 1107 |
"x = <<x>>, sqrt = <<x.sqrt()>>\n"; |
| 1108 |
|
| 1109 |
x = 987.65432; |
| 1110 |
"x = <<x>>, sqrt = <<x.sqrt()>>\n"; |
| 1111 |
|
| 1112 |
x = 9876.5432; |
| 1113 |
"x = <<x>>, sqrt = <<x.sqrt()>>\n"; |
| 1114 |
|
| 1115 |
x = 2.0000000; |
| 1116 |
"x = <<x>>, sqrt = <<x.sqrt()>>\n"; |
| 1117 |
|
| 1118 |
x = 0.20000000; |
| 1119 |
"x = <<x>>, sqrt = <<x.sqrt()>>\n"; |
| 1120 |
|
| 1121 |
"\b"; |
| 1122 |
|
| 1123 |
/* |
| 1124 |
* log |
| 1125 |
*/ |
| 1126 |
x = 3.04050607e-10; |
| 1127 |
"x = <<x.formatString(10, BignumExp)>>, ln = <<x.logE()>>\n"; |
| 1128 |
|
| 1129 |
x = 0.50267771; |
| 1130 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1131 |
|
| 1132 |
x = 0.750750750; |
| 1133 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1134 |
|
| 1135 |
x = 0.999888777; |
| 1136 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1137 |
|
| 1138 |
x = 1.00000000; |
| 1139 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1140 |
|
| 1141 |
x = 1.00000123; |
| 1142 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1143 |
|
| 1144 |
x = 1.99999999; |
| 1145 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1146 |
|
| 1147 |
x = 2.00000001; |
| 1148 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1149 |
|
| 1150 |
x = 11.7512345; |
| 1151 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1152 |
|
| 1153 |
x = 1234567890.; |
| 1154 |
"x = <<x>>, ln = <<x.logE()>>\n"; |
| 1155 |
|
| 1156 |
x = 9.8765432e50; |
| 1157 |
"x = <<x.formatString(10, BignumExp)>>, ln = <<x.logE()>>\n"; |
| 1158 |
|
| 1159 |
"\b"; |
| 1160 |
|
| 1161 |
/* |
| 1162 |
* exp |
| 1163 |
*/ |
| 1164 |
x = 5.000000e-17; |
| 1165 |
"x = <<x.formatString(10, BignumExp)>>, exp = <<x.expE()>>\n"; |
| 1166 |
|
| 1167 |
x = -5.000000e-17; |
| 1168 |
"x = <<x.formatString(10, BignumExp)>>, exp = <<x.expE()>>\n"; |
| 1169 |
|
| 1170 |
x = .000500000; |
| 1171 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1172 |
|
| 1173 |
x = -.000500000; |
| 1174 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1175 |
|
| 1176 |
x = .500000; |
| 1177 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1178 |
|
| 1179 |
x = -.500000; |
| 1180 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1181 |
|
| 1182 |
x = 1.00000; |
| 1183 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1184 |
|
| 1185 |
x = -1.00000; |
| 1186 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1187 |
|
| 1188 |
x = 1.50000; |
| 1189 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1190 |
|
| 1191 |
x = -1.50000; |
| 1192 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1193 |
|
| 1194 |
x = 2.30000; |
| 1195 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1196 |
|
| 1197 |
x = -2.30000; |
| 1198 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1199 |
|
| 1200 |
x = 15.00000; |
| 1201 |
"x = <<x>>, exp = <<x.expE().formatString(10, BignumExp)>>\n"; |
| 1202 |
|
| 1203 |
x = -15.0000; |
| 1204 |
"x = <<x>>, exp = <<x.expE().formatString(10, BignumExp)>>\n"; |
| 1205 |
|
| 1206 |
x = 150.000000; |
| 1207 |
"x = <<x>>, exp = <<x.expE().formatString(10, BignumExp)>>\n"; |
| 1208 |
|
| 1209 |
x = -150.00000; |
| 1210 |
"x = <<x>>, exp = <<x.expE().formatString(10, BignumExp)>>\n"; |
| 1211 |
|
| 1212 |
x = 1500.; |
| 1213 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1214 |
|
| 1215 |
x = -1500.; |
| 1216 |
"x = <<x>>, exp = <<x.expE()>>\n"; |
| 1217 |
|
| 1218 |
"\b"; |
| 1219 |
|
| 1220 |
/* |
| 1221 |
* log10 tests |
| 1222 |
*/ |
| 1223 |
x = 0.00001000; |
| 1224 |
"x = <<x>>, log10 = <<x.log10()>>\n"; |
| 1225 |
|
| 1226 |
x = 0.10000000; |
| 1227 |
"x = <<x>>, log10 = <<x.log10()>>\n"; |
| 1228 |
|
| 1229 |
x = 1.00000000; |
| 1230 |
"x = <<x>>, log10 = <<x.log10()>>\n"; |
| 1231 |
|
| 1232 |
x = 10.0000000; |
| 1233 |
"x = <<x>>, log10 = <<x.log10()>>\n"; |
| 1234 |
|
| 1235 |
x = 1.000000e23; |
| 1236 |
"x = <<x.formatString(10, BignumExp)>>, log10 = <<x.log10()>>\n"; |
| 1237 |
|
| 1238 |
x = 1234567890.; |
| 1239 |
"x = <<x>>, log10 = <<x.log10()>>\n"; |
| 1240 |
|
| 1241 |
x = 345676543.; |
| 1242 |
"x = <<x>>, log10 = <<x.log10()>>\n"; |
| 1243 |
|
| 1244 |
"\b"; |
| 1245 |
|
| 1246 |
/* |
| 1247 |
* power tests |
| 1248 |
*/ |
| 1249 |
x = 5.123456; |
| 1250 |
y = 7.890123; |
| 1251 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1252 |
|
| 1253 |
x = 52.123456; |
| 1254 |
y = -7.890123; |
| 1255 |
"x = <<x>>, y = <<y>>, |
| 1256 |
x^y = <<x.raiseToPower(y).formatString(10, BignumExp)>>\n"; |
| 1257 |
|
| 1258 |
x = -3.123456; |
| 1259 |
y = 7.; |
| 1260 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1261 |
|
| 1262 |
x = -5.123456; |
| 1263 |
y = -7.; |
| 1264 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1265 |
|
| 1266 |
x = -3.123456; |
| 1267 |
y = 6.; |
| 1268 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1269 |
|
| 1270 |
x = -5.123456; |
| 1271 |
y = -6.; |
| 1272 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1273 |
|
| 1274 |
x = 0.00005234991; |
| 1275 |
y = 0.00006781234; |
| 1276 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1277 |
|
| 1278 |
x = 0.000000; |
| 1279 |
y = 1.000000; |
| 1280 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1281 |
|
| 1282 |
x = 12.000000; |
| 1283 |
y = 0.000000; |
| 1284 |
"x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; |
| 1285 |
|
| 1286 |
x = 0.000000; |
| 1287 |
y = 0.000000; |
| 1288 |
try { "x = <<x>>, y = <<y>>, x^y = <<x.raiseToPower(y)>>\n"; } |
| 1289 |
catch (RuntimeError err) { "error: <<err.exceptionMessage>>\n"; } |
| 1290 |
|
| 1291 |
"\b"; |
| 1292 |
|
| 1293 |
/* |
| 1294 |
* hyperbolic sine, cosine, and tangent |
| 1295 |
*/ |
| 1296 |
|
| 1297 |
x = 0.0000000; |
| 1298 |
"x = <<x>>, sinh=<<x.sinh()>>, cosh=<<x.cosh()>>, tahn=<<x.tanh()>>\n"; |
| 1299 |
|
| 1300 |
x = 1.0000000; |
| 1301 |
"x = <<x>>, sinh=<<x.sinh()>>, cosh=<<x.cosh()>>, tahn=<<x.tanh()>>\n"; |
| 1302 |
|
| 1303 |
x = -1.0000000; |
| 1304 |
"x = <<x>>, sinh=<<x.sinh()>>, cosh=<<x.cosh()>>, tahn=<<x.tanh()>>\n"; |
| 1305 |
|
| 1306 |
x = 2.5300000; |
| 1307 |
"x = <<x>>, sinh=<<x.sinh()>>, cosh=<<x.cosh()>>, tahn=<<x.tanh()>>\n"; |
| 1308 |
|
| 1309 |
x = -2.5300000; |
| 1310 |
"x = <<x>>, sinh=<<x.sinh()>>, cosh=<<x.cosh()>>, tahn=<<x.tanh()>>\n"; |
| 1311 |
|
| 1312 |
"\b"; |
| 1313 |
|
| 1314 |
/* |
| 1315 |
* min/max |
| 1316 |
*/ |
| 1317 |
x = 1.000; |
| 1318 |
y = -3.000; |
| 1319 |
z = 2.000; |
| 1320 |
"x = <<x>>, y = <<y>>, z = <<z>>, min = <<min(x, y, z)>>, |
| 1321 |
max = <<max(x, y, z)>>\n"; |
| 1322 |
"(x,y,z,-11,7): min = <<min(x, y, z, -11, 7)>>, |
| 1323 |
max = <<max(x, y, z, -11, 7)>>\n"; |
| 1324 |
"max(z, y, x) = <<max(z, y, x)>>, max(y, x, z) = <<max(y, x, z)>>\n"; |
| 1325 |
"min(z, y, x) = <<min(z, y, x)>>, min(y, x, z) = <<min(y, x, z)>>\n"; |
| 1326 |
|
| 1327 |
"\b"; |
| 1328 |
} |
| 1329 |
|
| 1330 |
bool(val) |
| 1331 |
{ |
| 1332 |
if (val) |
| 1333 |
"true"; |
| 1334 |
else |
| 1335 |
"nil"; |
| 1336 |
} |
| 1337 |
|
| 1338 |
preinit() |
| 1339 |
{ |
| 1340 |
} |
| 1341 |
|