Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Some simple math and absolute values

by 1nickt (Canon)
on May 23, 2020 at 03:20 UTC ( [id://11117141]=note: print w/replies, xml ) Need Help??


in reply to Some simple math and absolute values

Hi,

I am not a math expert nor an algorithm expert nor a golfer, Perl or otherwise, but maybe something like this?

my $price = ($wt || 1) * 10; $price = 10 * $price/abs($price) if abs($price) < 10;

Output:

perl blrg.pl 2.3 Price: 23 Next Weight: .3 Price: 10 Next Weight: 0 Price: 10 Next Weight: -.3 Price: -10 Next Weight: -2.3 Price: -23 Next Weight:

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Some simple math and absolute values
by sidmuchrock (Novice) on May 23, 2020 at 14:40 UTC
    This was what I was missing last night! I kept trying to say if $wt/abs($wt) and it was dying in the 0 case, but by turning the 0 to $min in the possible total and then checking $total/abs($total) that solved. it. Thank you.
    $total = ($wt || $min) * $price; $total = $total/abs($total) * $price * $min if abs($wt) < $min +;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found