github.com/mithrandie/csvq@v1.18.1/docs/_posts/2006-01-02-numeric-functions.md (about) 1 --- 2 layout: default 3 title: Numeric Functions - Reference Manual - csvq 4 category: reference 5 --- 6 7 # Numeric Functions 8 9 | name | description | 10 |:--------------------------------------|:------------------------------------------------------------------------------------------| 11 | [ABS](#abs) | Return the absolute value of a number | 12 | [ACOS](#acos) | Return the arc cosine of a number | 13 | [ACOSH](#acosh) | Return the inverse hyperbolic cosine of a number | 14 | [ASIN](#asin) | Return the arc sine of a number | 15 | [ASINH](#asinh) | Return the inverse hyperbolic sine of a number | 16 | [ATAN](#atan) | Return the arc tangent of a number | 17 | [ATAN2](#atan2) | Return the arc tangent of two numbers | 18 | [ATANH](#atanh) | Return the inverse hyperbolic tangent of a number | 19 | [CBRT](#cbrt) | Return the cube root of a number | 20 | [CEIL](#ceil) | Round a number up | 21 | [COS](#cos) | Return the cosine of a number | 22 | [COSH](#cosh) | Return the hyperbolic cosine of a number | 23 | [EXP](#exp) | Return the value of base _e_ raised to the power of a number | 24 | [EXP2](#exp2) | Return the value of base _2_ raised to the power of a number | 25 | [EXPM1](#expm1) | Return the value of base _e_ rised to the power of a number minus 1 | 26 | [FLOOR](#floor) | Round a number down | 27 | [IS_INF](#is_inf) | Return whether _number_ is an infinity | 28 | [IS_NAN](#is_nan) | Return whether _number_ is a NaN | 29 | [LOG](#log) | Return the natural logarithm of a number | 30 | [LOG10](#log10) | Return the decimal logarithm of a number | 31 | [LOG1P](#log1p) | Return the natural logarithm of 1 plus a number | 32 | [LOG2](#log2) | Return the binary logarithm of a number | 33 | [LOGB](#logb) | Return the binary exponent of a number | 34 | [POW](#pow) | Returns the value of a number raised to the power of another number | 35 | [ROUND](#round) | Round a number | 36 | [SIN](#sin) | Return the sine of a number | 37 | [SINH](#sinh) | Return the hyperbolic sine of a number | 38 | [SQRT](#sqrt) | Return the square root of a number | 39 | [TAN](#tan) | Return the tangent of a number | 40 | [TANH](#tanh) | Return the hyperbolic tangent of a number | 41 | [BIN_TO_DEC](#bin_to_dec) | Convert a string representing a binary number to an integer | 42 | [OCT_TO_DEC](#oct_to_dec) | Convert a string representing a octal number to an integer | 43 | [HEX_TO_DEC](#hex_to_dec) | Convert a string representing a hexadecimal number to an integer | 44 | [ENOTATION_TO_DEC](#enotation_to_dec) | Convert a string representing a number with exponential notation to an integer or a float | 45 | [BIN](#bin) | Convert an integer to a string representing the bynary number | 46 | [OCT](#oct) | Convert an integer to a string representing the octal number | 47 | [HEX](#hex) | Convert an integer to a string representing the hexadecimal number | 48 | [ENOTATION](#enotation) | Convert a float to a string representing the number with exponential notation | 49 | [NUMBER_FORMAT](#number_format) | Convert a number to a string representing the number with separators | 50 | [RAND](#rand) | Return a pseudo-random number | 51 52 > _e_ is the base of natural logarithms 53 54 ## Definitions 55 56 ### ABS 57 {: #abs} 58 59 ``` 60 ABS(number) 61 ``` 62 63 _number_ 64 : [float]({{ '/reference/value.html#float' | relative_url }}) 65 66 _return_ 67 : [float]({{ '/reference/value.html#float' | relative_url }}) 68 69 Returns the absolute value of _number_ 70 71 ### ACOS 72 {: #acos} 73 74 ``` 75 ACOS(number) 76 ``` 77 78 _number_ 79 : [float]({{ '/reference/value.html#float' | relative_url }}) 80 81 _return_ 82 : [float]({{ '/reference/value.html#float' | relative_url }}) 83 84 Returns the arc cosine of _number_. 85 86 ### ACOSH 87 {: #acosh} 88 89 ``` 90 ACOSH(number) 91 ``` 92 93 _number_ 94 : [float]({{ '/reference/value.html#float' | relative_url }}) 95 96 _return_ 97 : [float]({{ '/reference/value.html#float' | relative_url }}) 98 99 Returns the inverse hyperbolic cosine of _number_. 100 101 ### ASIN 102 {: #asin} 103 104 ``` 105 ASIN(number) 106 ``` 107 108 _number_ 109 : [float]({{ '/reference/value.html#float' | relative_url }}) 110 111 _return_ 112 : [float]({{ '/reference/value.html#float' | relative_url }}) 113 114 Returns the arc sine of _number_. 115 116 ### ASINH 117 {: #asinh} 118 119 ``` 120 ASINH(number) 121 ``` 122 123 _number_ 124 : [float]({{ '/reference/value.html#float' | relative_url }}) 125 126 _return_ 127 : [float]({{ '/reference/value.html#float' | relative_url }}) 128 129 Returns the inverse hyperbolic sine of _number_. 130 131 ### ATAN 132 {: #atan} 133 134 ``` 135 ATAN(number) 136 ``` 137 138 _number_ 139 : [float]({{ '/reference/value.html#float' | relative_url }}) 140 141 _return_ 142 : [float]({{ '/reference/value.html#float' | relative_url }}) 143 144 Returns the arc tangent of _number_. 145 146 ### ATAN2 147 {: #atan2} 148 149 ``` 150 ATAN2(number2, number1) 151 ``` 152 153 _number2_ 154 : [float]({{ '/reference/value.html#float' | relative_url }}) 155 156 _number1_ 157 : [float]({{ '/reference/value.html#float' | relative_url }}) 158 159 _return_ 160 : [float]({{ '/reference/value.html#float' | relative_url }}) 161 162 Returns the arc tangent of _number2_ / _number1_, using the signs of the two to determine the quadrant of the returns value. 163 164 ### ATANH 165 {: #atanh} 166 167 ``` 168 ATANH(number) 169 ``` 170 171 _number_ 172 : [float]({{ '/reference/value.html#float' | relative_url }}) 173 174 _return_ 175 : [float]({{ '/reference/value.html#float' | relative_url }}) 176 177 Returns the inverse hyperbolic tangent of _number_. 178 179 ### CBRT 180 {: #cbrt} 181 182 ``` 183 CBRT(number) 184 ``` 185 186 _number_ 187 : [float]({{ '/reference/value.html#float' | relative_url }}) 188 189 _return_ 190 : [float]({{ '/reference/value.html#float' | relative_url }}) 191 192 Returns the cube root of _number_. 193 194 ### CEIL 195 {: #ceil} 196 197 ``` 198 CEIL(number) 199 ``` 200 201 _number_ 202 : [float]({{ '/reference/value.html#float' | relative_url }}) 203 204 _return_ 205 : [float]({{ '/reference/value.html#float' | relative_url }}) 206 207 Rounds _number_ up to an integer value. 208 209 ``` 210 CEIL(number, place) 211 ``` 212 213 _number_ 214 : [float]({{ '/reference/value.html#float' | relative_url }}) 215 216 _place_ 217 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 218 219 _return_ 220 : [float]({{ '/reference/value.html#float' | relative_url }}) 221 222 Rounds _number_ up to _place_ decimal place. 223 If _place_ is a negative number, _place_ represents the place in the integer part. 224 225 ### COS 226 {: #cos} 227 228 ``` 229 COS(number) 230 ``` 231 232 _number_ 233 : [float]({{ '/reference/value.html#float' | relative_url }}) 234 235 _return_ 236 : [float]({{ '/reference/value.html#float' | relative_url }}) 237 238 Returns the cosine of _number_. 239 240 ### COSH 241 {: #cosh} 242 243 ``` 244 COSH(number) 245 ``` 246 247 _number_ 248 : [float]({{ '/reference/value.html#float' | relative_url }}) 249 250 _return_ 251 : [float]({{ '/reference/value.html#float' | relative_url }}) 252 253 Returns the hyperbolic cosine of _number_. 254 255 ### EXP 256 {: #exp} 257 258 ``` 259 EXP(number) 260 ``` 261 262 _number_ 263 : [float]({{ '/reference/value.html#float' | relative_url }}) 264 265 _return_ 266 : [float]({{ '/reference/value.html#float' | relative_url }}) 267 268 Returns the value of base _e_ raised to the power of _number_. 269 270 ### EXP2 271 {: #exp2} 272 273 ``` 274 EXP2(number) 275 ``` 276 277 _number_ 278 : [float]({{ '/reference/value.html#float' | relative_url }}) 279 280 _return_ 281 : [float]({{ '/reference/value.html#float' | relative_url }}) 282 283 Returns the value of base _2_ raised to the power of _number_. 284 285 ### EXPM1 286 {: #expm1} 287 288 ``` 289 EXPM1(number) 290 ``` 291 292 _number_ 293 : [float]({{ '/reference/value.html#float' | relative_url }}) 294 295 _return_ 296 : [float]({{ '/reference/value.html#float' | relative_url }}) 297 298 Returns the value of base _e_ rised to the power of _number_ minus 1. 299 300 ### FLOOR 301 {: #floor} 302 303 ``` 304 FLOOR(number) 305 ``` 306 307 _number_ 308 : [float]({{ '/reference/value.html#float' | relative_url }}) 309 310 _return_ 311 : [float]({{ '/reference/value.html#float' | relative_url }}) 312 313 Rounds _number_ down to an integer value. 314 315 ``` 316 FLOOR(number, place) 317 ``` 318 319 _number_ 320 : [float]({{ '/reference/value.html#float' | relative_url }}) 321 322 _place_ 323 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 324 325 _return_ 326 : [float]({{ '/reference/value.html#float' | relative_url }}) 327 328 Rounds _number_ down to _place_ decimal place. 329 If _place_ is a negative number, _place_ represents the place in the integer part. 330 331 ### IS_INF 332 {: #is_inf} 333 334 ``` 335 IS_INF(number [, sign]) 336 ``` 337 338 _number_ 339 : [float]({{ '/reference/value.html#float' | relative_url }}) 340 341 _sign_ 342 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 343 344 The default is _0_. 345 346 _return_ 347 : [ternary]({{ '/reference/value.html#ternary' | relative_url }}) 348 349 Returns whether _number_ is an infinity. 350 If _sign_ is greater than 0, then returns whether _number_ is a positive infinity. 351 If _sign_ is less than 0, then returns whether _number_ is a negative infinity. 352 If _sign_ is 0, then returns whether _number_ is either infinity. 353 354 ### IS_NAN 355 {: #is_nan} 356 357 ``` 358 IS_NAN(number) 359 ``` 360 361 _number_ 362 : [float]({{ '/reference/value.html#float' | relative_url }}) 363 364 _return_ 365 : [ternary]({{ '/reference/value.html#ternary' | relative_url }}) 366 367 Returns whether _number_ is a NaN. 368 369 ### LOG 370 {: #log} 371 372 ``` 373 LOG(number) 374 ``` 375 376 _number_ 377 : [float]({{ '/reference/value.html#float' | relative_url }}) 378 379 _return_ 380 : [float]({{ '/reference/value.html#float' | relative_url }}) 381 382 Returns the natural logarithm of _number_. 383 384 ### LOG10 385 {: #log10} 386 387 ``` 388 LOG10(number) 389 ``` 390 391 _number_ 392 : [float]({{ '/reference/value.html#float' | relative_url }}) 393 394 _return_ 395 : [float]({{ '/reference/value.html#float' | relative_url }}) 396 397 Returns the decimal logarithm of _number_. 398 399 ### LOG1P 400 {: #log1p} 401 402 ``` 403 LOG1P(number) 404 ``` 405 406 _number_ 407 : [float]({{ '/reference/value.html#float' | relative_url }}) 408 409 _return_ 410 : [float]({{ '/reference/value.html#float' | relative_url }}) 411 412 Returns the natural logarithm of 1 plus _number_. 413 414 ### LOG2 415 {: #log2} 416 417 ``` 418 LOG2(number) 419 ``` 420 421 _number_ 422 : [float]({{ '/reference/value.html#float' | relative_url }}) 423 424 _return_ 425 : [float]({{ '/reference/value.html#float' | relative_url }}) 426 427 Returns the binary logarithm of _number_. 428 429 ### LOGB 430 {: #logb} 431 432 ``` 433 LOGB(number) 434 ``` 435 436 _number_ 437 : [float]({{ '/reference/value.html#float' | relative_url }}) 438 439 _return_ 440 : [float]({{ '/reference/value.html#float' | relative_url }}) 441 442 Returns the binary exponent of _number_. 443 444 ### POW 445 {: #pow} 446 447 ``` 448 POW(base, exponent) 449 ``` 450 451 _base_ 452 : [float]({{ '/reference/value.html#float' | relative_url }}) 453 454 _exponent_ 455 : [float]({{ '/reference/value.html#float' | relative_url }}) 456 457 _return_ 458 : [float]({{ '/reference/value.html#float' | relative_url }}) 459 460 Returns the value of _base_ raised to the power of _exponent_. 461 462 ### ROUND 463 {: #round} 464 465 ``` 466 ROUND(number) 467 ``` 468 469 _number_ 470 : [float]({{ '/reference/value.html#float' | relative_url }}) 471 472 _return_ 473 : [float]({{ '/reference/value.html#float' | relative_url }}) 474 475 Rounds _number_ to an integer value. 476 477 ``` 478 ROUND(number, place) 479 ``` 480 481 _number_ 482 : [float]({{ '/reference/value.html#float' | relative_url }}) 483 484 _place_ 485 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 486 487 _return_ 488 : [float]({{ '/reference/value.html#float' | relative_url }}) 489 490 Rounds _number_ to _place_ decimal place. 491 If _place_ is a negative number, _place_ represents the place in the integer part. 492 493 ### SIN 494 {: #sin} 495 496 ``` 497 SIN(number) 498 ``` 499 500 _number_ 501 : [float]({{ '/reference/value.html#float' | relative_url }}) 502 503 _return_ 504 : [float]({{ '/reference/value.html#float' | relative_url }}) 505 506 Returns the sine of _number_. 507 508 ### SINH 509 {: #sinh} 510 511 ``` 512 SINH(number) 513 ``` 514 515 _number_ 516 : [float]({{ '/reference/value.html#float' | relative_url }}) 517 518 _return_ 519 : [float]({{ '/reference/value.html#float' | relative_url }}) 520 521 Returns the hyperbolic sine of _number_. 522 523 ### SQRT 524 {: #sqrt} 525 526 ``` 527 SQRT(number) 528 ``` 529 530 _number_ 531 : [float]({{ '/reference/value.html#float' | relative_url }}) 532 533 _return_ 534 : [float]({{ '/reference/value.html#float' | relative_url }}) 535 536 Returns the square root of _number_. 537 538 ### TAN 539 {: #tan} 540 541 ``` 542 TAN(number) 543 ``` 544 545 _number_ 546 : [float]({{ '/reference/value.html#float' | relative_url }}) 547 548 _return_ 549 : [float]({{ '/reference/value.html#float' | relative_url }}) 550 551 Returns the tangent of _number_. 552 553 ### TANH 554 {: #tanh} 555 556 ``` 557 TANH(number) 558 ``` 559 560 _number_ 561 : [float]({{ '/reference/value.html#float' | relative_url }}) 562 563 _return_ 564 : [float]({{ '/reference/value.html#float' | relative_url }}) 565 566 Returns the hyperbolic tangent of _number_. 567 568 ### BIN_TO_DEC 569 {: #bin_to_dec} 570 571 ``` 572 BIN_TO_DEC(bin) 573 ``` 574 575 _bin_ 576 : [string]({{ '/reference/value.html#string' | relative_url }}) 577 578 _return_ 579 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 580 581 Converts _bin_ representing a binary number to an integer. 582 583 ### OCT_TO_DEC 584 {: #oct_to_dec} 585 586 ``` 587 OCT_TO_DEC(oct) 588 ``` 589 590 _oct_ 591 : [string]({{ '/reference/value.html#string' | relative_url }}) 592 593 _return_ 594 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 595 596 Converts _hex_ representing an octal number to an integer. 597 598 ### HEX_TO_DEC 599 {: #hex_to_dec} 600 601 ``` 602 HEX_TO_DEC(hex) 603 ``` 604 605 _hex_ 606 : [string]({{ '/reference/value.html#string' | relative_url }}) 607 608 _return_ 609 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 610 611 Converts _hex_ representing a hexadecimal number to an integer. 612 613 ### ENOTATION_TO_DEC 614 {: #enotation_to_dec} 615 616 ``` 617 ENOTATION_TO_DEC(enotation) 618 ``` 619 620 _enotation_ 621 : [string]({{ '/reference/value.html#string' | relative_url }}) 622 623 _return_ 624 : [float]({{ '/reference/value.html#float' | relative_url }}) 625 626 Converts _enotation_ representing a number with exponential notation to a float. 627 628 ### BIN 629 {: #bin} 630 631 ``` 632 BIN(integer) 633 ``` 634 635 _integer_ 636 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 637 638 _return_ 639 : [string]({{ '/reference/value.html#string' | relative_url }}) 640 641 Converts _integer_ to a string representing the binary number. 642 643 ### OCT 644 {: #oct} 645 646 ``` 647 OCT(integer) 648 ``` 649 650 _integer_ 651 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 652 653 _return_ 654 : [string]({{ '/reference/value.html#string' | relative_url }}) 655 656 Converts _integer_ to a string representing the octal number. 657 658 ### HEX 659 {: #hex} 660 661 ``` 662 HEX(integer) 663 ``` 664 665 _integer_ 666 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 667 668 _return_ 669 : [string]({{ '/reference/value.html#string' | relative_url }}) 670 671 Converts _integer_ to a string representing the hexadecimal number. 672 673 ### ENOTATION 674 {: #enotation} 675 676 ``` 677 ENOTATION(float) 678 ``` 679 680 _float_ 681 : [float]({{ '/reference/value.html#float' | relative_url }}) 682 683 _return_ 684 : [string]({{ '/reference/value.html#string' | relative_url }}) 685 686 Converts _float_ to a string representing the number with exponential notation. 687 688 689 ### NUMBER_FORMAT 690 {: #number_format} 691 692 ``` 693 NUMBER_FORMAT(number [, precision, decimalPoint, thousandsSeparator, decimalSeparator]) 694 ``` 695 696 _number_ 697 : [float]({{ '/reference/value.html#float' | relative_url }}) or [integer]({{ '/reference/value.html#integer' | relative_url }}) 698 699 _precision_ 700 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 701 702 The default is -1. 703 -1 is the special precision to determine the number of digits automatically. 704 705 _decimalPoint_ 706 : [string]({{ '/reference/value.html#string' | relative_url }}) 707 708 The default is ".". 709 710 _thousandsSeparator_ 711 : [string]({{ '/reference/value.html#string' | relative_url }}) 712 713 The default is ",". 714 715 _decimalSeparator_ 716 : [string]({{ '/reference/value.html#string' | relative_url }}) 717 718 The default is empty string. 719 720 _return_ 721 : [string]({{ '/reference/value.html#string' | relative_url }}) 722 723 Converts _number_ to a string representing the number with separators. 724 725 726 ### RAND 727 {: #rand} 728 729 ``` 730 RAND() 731 ``` 732 733 _return_ 734 : [float]({{ '/reference/value.html#float' | relative_url }}) 735 736 Returns a random float greater than or equal to 0.0 and less than 1.0. 737 738 ``` 739 RAND(min, max) 740 ``` 741 742 _min_ 743 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 744 745 _max_ 746 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 747 748 _return_ 749 : [integer]({{ '/reference/value.html#integer' | relative_url }}) 750 751 Returns a random integer between _min_ and _max_.