Home » Julia

flipsign() Function with Example in Julia

Julia | flipsign() function: In this tutorial, we are going to learn about the flipsign() function with example in the Julia programming language.
Submitted by IncludeHelp, on April 04, 2020

Julia | flipsign() function

flipsign() function is a library function in Julia programming language, it accepts two values as parameters and returns a value with the magnitude of first value and sign of the first value*second value i.e. it returns the first value with its flipped sign if the second value is negative.

Syntax:

    flipsign(val1, val2)

Parameter(s):

  • val1 – represents the magnitude value i.e. first value that will be used as a magnitude to construct the return value.
  • val2 – represents the sign value.

Return value:

The return type of this method is Int64, it returns val1 with its flipped sign if val2 is negative.

Example:

    Input:
    val1 = 0
    val2 = 0
    Output:
    flipsign(val1, val2): 0

    Input:
    val1 = -123
    val2 = 10
    Output:
    flipsign(val1, val2): -123

    Input:
    val1 = 123
    val2 = -1
    Output:
    flipsign(val1, val2): -123

    Input:
    val1 = -123
    val2 = -1
    Output:
    flipsign(val1, val2): 123

Program:

# flipsign() Function with Example in Julia

val1 = 0
val2 = 0
println("val1: ", val1)
println("val2: ", val2)
println("flipsign(val1, val2): ", flipsign(val1, val2))

val1 = -10
val2 = 0
println("val1: ", val1)
println("val2: ", val2)
println("flipsign(val1, val2): ", flipsign(val1, val2))

val1 = 10
val2 = -10
println("val1: ", val1)
println("val2: ", val2)
println("flipsign(val1, val2): ", flipsign(val1, val2))

val1 = -10.20
val2 = 1
println("val1: ", val1)
println("val2: ", val2)
println("flipsign(val1, val2): ", flipsign(val1, val2))

val1 = -10.23
val2 = -10
println("val1: ", val1)
println("val2: ", val2)
println("flipsign(val1, val2): ", flipsign(val1, val2))

# printing the return type of flipsign()
println("typeof(flipsign(123, -10)): ", typeof(flipsign(123, -10)))

Output

val1: 0
val2: 0
flipsign(val1, val2): 0
val1: -10
val2: 0
flipsign(val1, val2): -10
val1: 10
val2: -10
flipsign(val1, val2): -10
val1: -10.2
val2: 1
flipsign(val1, val2): -10.2
val1: -10.23
val2: -10
flipsign(val1, val2): 10.23
typeof(flipsign(123, -10)): Int64


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.